home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 6 / CU Amiga Magazine's Super CD-ROM 06 (1996)(EMAP Images)(GB)(Track 1 of 4)[!][issue 1997-01].iso / cucd / prog / gnu-c / src / gcc-2.7.0-amiga / cp / class.c < prev    next >
C/C++ Source or Header  |  1995-06-15  |  155KB  |  5,011 lines

  1. /* Functions related to building classes and their related objects.
  2.    Copyright (C) 1987, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
  3.    Contributed by Michael Tiemann (tiemann@cygnus.com)
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 59 Temple Place - Suite 330,
  20. Boston, MA 02111-1307, USA.  */
  21.  
  22.  
  23. /* High-level class interface. */
  24.  
  25. #include "config.h"
  26. #include "tree.h"
  27. #include <stdio.h>
  28. #include "cp-tree.h"
  29. #include "flags.h"
  30. #include "rtl.h"
  31. #include "output.h"
  32.  
  33. #include "obstack.h"
  34. #define obstack_chunk_alloc xmalloc
  35. #define obstack_chunk_free free
  36.  
  37. extern struct obstack permanent_obstack;
  38.  
  39. /* This is how we tell when two virtual member functions are really the
  40.    same. */
  41. #define SAME_FN(FN1DECL, FN2DECL) (DECL_ASSEMBLER_NAME (FN1DECL) == DECL_ASSEMBLER_NAME (FN2DECL))
  42.  
  43. extern void set_class_shadows PROTO ((tree));
  44.  
  45. /* Way of stacking class types.  */
  46. static tree *current_class_base, *current_class_stack;
  47. static int current_class_stacksize;
  48. int current_class_depth;
  49.  
  50. struct class_level
  51. {
  52.   /* The previous class level.  */
  53.   struct class_level *level_chain;
  54.  
  55.   /* The class instance variable, as a PARM_DECL.  */
  56.   tree decl;
  57.   /* The class instance variable, as an object.  */
  58.   tree object;
  59.   /* The virtual function table pointer
  60.      for the class instance variable.  */
  61.   tree vtable_decl;
  62.  
  63.   /* Name of the current class.  */
  64.   tree name;
  65.   /* Type of the current class.  */
  66.   tree type;
  67.  
  68.   /* Flags for this class level.  */
  69.   int this_is_variable;
  70.   int memoized_lookups;
  71.   int save_memoized;
  72.   int unused;
  73. };
  74.  
  75. tree current_class_decl, C_C_D;    /* PARM_DECL: the class instance variable */
  76.  
  77. /* The following two can be derived from the previous one */
  78. tree current_class_name;    /* IDENTIFIER_NODE: name of current class */
  79. tree current_class_type;    /* _TYPE: the type of the current class */
  80. tree previous_class_type;    /* _TYPE: the previous type that was a class */
  81. tree previous_class_values;        /* TREE_LIST: copy of the class_shadowed list
  82.                    when leaving an outermost class scope.  */
  83. static tree get_vfield_name PROTO((tree));
  84. tree the_null_vtable_entry;
  85.  
  86. /* Way of stacking language names.  */
  87. tree *current_lang_base, *current_lang_stack;
  88. int current_lang_stacksize;
  89.  
  90. /* Names of languages we recognize.  */
  91. tree lang_name_c, lang_name_cplusplus;
  92. tree current_lang_name;
  93.  
  94. /* When layout out an aggregate type, the size of the
  95.    basetypes (virtual and non-virtual) is passed to layout_record
  96.    via this node.  */
  97. static tree base_layout_decl;
  98.  
  99. /* Variables shared between class.c and call.c.  */
  100.  
  101. int n_vtables = 0;
  102. int n_vtable_entries = 0;
  103. int n_vtable_searches = 0;
  104. int n_vtable_elems = 0;
  105. int n_convert_harshness = 0;
  106. int n_compute_conversion_costs = 0;
  107. int n_build_method_call = 0;
  108. int n_inner_fields_searched = 0;
  109.  
  110. /* Virtual baseclass things.  */
  111. tree
  112. build_vbase_pointer (exp, type)
  113.      tree exp, type;
  114. {
  115.   char *name;
  116.  
  117.   name = (char *) alloca (TYPE_NAME_LENGTH (type) + sizeof (VBASE_NAME) + 1);
  118.   sprintf (name, VBASE_NAME_FORMAT, TYPE_NAME_STRING (type));
  119.   return build_component_ref (exp, get_identifier (name), 0, 0);
  120. }
  121.  
  122. /* Is the type of the EXPR, the complete type of the object?
  123.    If we are going to be wrong, we must be conservative, and return 0. */
  124. int
  125. complete_type_p (expr)
  126.      tree expr;
  127. {
  128.   tree type = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
  129.   while (1)
  130.     {
  131.       switch (TREE_CODE (expr))
  132.     {
  133.     case SAVE_EXPR:
  134.     case INDIRECT_REF:
  135.     case ADDR_EXPR:
  136.     case NOP_EXPR:
  137.     case CONVERT_EXPR:
  138.       expr = TREE_OPERAND (expr, 0);
  139.       continue;
  140.  
  141.     case CALL_EXPR: 
  142.       if (! TREE_HAS_CONSTRUCTOR (expr))
  143.         break;
  144.       /* fall through... */
  145.     case VAR_DECL:
  146.     case FIELD_DECL:
  147.       if (TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
  148.           && IS_AGGR_TYPE (TREE_TYPE (TREE_TYPE (expr)))
  149.           && TYPE_MAIN_VARIANT (TREE_TYPE (expr)) == type)
  150.         return 1;
  151.       /* fall through... */
  152.     case TARGET_EXPR:
  153.     case PARM_DECL:
  154.       if (IS_AGGR_TYPE (TREE_TYPE (expr))
  155.           && TYPE_MAIN_VARIANT (TREE_TYPE (expr)) == type)
  156.         return 1;
  157.       /* fall through... */
  158.     case PLUS_EXPR:
  159.     default:
  160.       break;
  161.     }
  162.       break;
  163.     }
  164.   return 0;
  165. }
  166.  
  167. /* Build multi-level access to EXPR using hierarchy path PATH.
  168.    CODE is PLUS_EXPR if we are going with the grain,
  169.    and MINUS_EXPR if we are not (in which case, we cannot traverse
  170.    virtual baseclass links).
  171.  
  172.    TYPE is the type we want this path to have on exit.
  173.  
  174.    ALIAS_THIS is non-zero if EXPR in an expression involving `this'.  */
  175. tree
  176. build_vbase_path (code, type, expr, path, alias_this)
  177.      enum tree_code code;
  178.      tree type, expr, path;
  179.      int alias_this;
  180. {
  181.   register int changed = 0;
  182.   tree last = NULL_TREE, last_virtual = NULL_TREE;
  183.   int nonnull = 0;
  184.   int fixed_type_p = resolves_to_fixed_type_p (expr, &nonnull);
  185.   tree null_expr = 0, nonnull_expr;
  186.   tree basetype;
  187.   tree offset = integer_zero_node;
  188.  
  189.   /* We need additional logic to convert back to the unconverted type
  190.      (the static type of the complete object), and then convert back
  191.      to the type we want.  Until that is done, or until we can
  192.      recognize when that is, we cannot do the short cut logic. (mrs) */
  193.   /* Do this, until we can undo any previous conversions.  See net35.C
  194.      for a testcase. */
  195.   fixed_type_p = complete_type_p (expr);
  196.  
  197.   if (!fixed_type_p && TREE_SIDE_EFFECTS (expr))
  198.     expr = save_expr (expr);
  199.   nonnull_expr = expr;
  200.  
  201.   if (BINFO_INHERITANCE_CHAIN (path))
  202.     {
  203.       tree reverse_path = NULL_TREE;
  204.  
  205.       while (path)
  206.     {
  207.       tree r = copy_node (path);
  208.       BINFO_INHERITANCE_CHAIN (r) = reverse_path;
  209.       reverse_path = r;
  210.       path = BINFO_INHERITANCE_CHAIN (path);
  211.     }
  212.       path = reverse_path;
  213.     }
  214.  
  215.   basetype = BINFO_TYPE (path);
  216.  
  217.   while (path)
  218.     {
  219.       if (TREE_VIA_VIRTUAL (path))
  220.     {
  221.       last_virtual = BINFO_TYPE (path);
  222.       if (code == PLUS_EXPR)
  223.         {
  224.           changed = ! fixed_type_p;
  225.  
  226.           if (changed)
  227.         {
  228.           extern int flag_assume_nonnull_objects;
  229.           tree ind;
  230.  
  231.           /* We already check for ambiguous things in the caller, just
  232.              find a path. */
  233.           if (last)
  234.             {
  235.               tree binfo = get_binfo (last, TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (nonnull_expr))), 0);
  236.               nonnull_expr = convert_pointer_to_real (binfo, nonnull_expr);
  237.             }
  238.           ind = build_indirect_ref (nonnull_expr, NULL_PTR);
  239.           nonnull_expr = build_vbase_pointer (ind, last_virtual);
  240.           if (nonnull == 0
  241.               && (TREE_CODE (type) == POINTER_TYPE
  242.               || !flag_assume_nonnull_objects)
  243.               && null_expr == NULL_TREE)
  244.             {
  245.               null_expr = build1 (NOP_EXPR, TYPE_POINTER_TO (last_virtual), integer_zero_node);
  246.               expr = build (COND_EXPR, TYPE_POINTER_TO (last_virtual),
  247.                     build (EQ_EXPR, boolean_type_node, expr,
  248.                        integer_zero_node),
  249.                     null_expr, nonnull_expr);
  250.             }
  251.         }
  252.           /* else we'll figure out the offset below.  */
  253.  
  254.           /* Happens in the case of parse errors.  */
  255.           if (nonnull_expr == error_mark_node)
  256.         return error_mark_node;
  257.         }
  258.       else
  259.         {
  260.           cp_error ("cannot cast up from virtual baseclass `%T'",
  261.               last_virtual);
  262.           return error_mark_node;
  263.         }
  264.     }
  265.       last = path;
  266.       path = BINFO_INHERITANCE_CHAIN (path);
  267.     }
  268.   /* LAST is now the last basetype assoc on the path.  */
  269.  
  270.   /* A pointer to a virtual base member of a non-null object
  271.      is non-null.  Therefore, we only need to test for zeroness once.
  272.      Make EXPR the canonical expression to deal with here.  */
  273.   if (null_expr)
  274.     {
  275.       TREE_OPERAND (expr, 2) = nonnull_expr;
  276.       TREE_TYPE (TREE_OPERAND (expr, 1)) = TREE_TYPE (nonnull_expr);
  277.     }
  278.   else
  279.     expr = nonnull_expr;
  280.  
  281.   /* If we go through any virtual base pointers, make sure that
  282.      casts to BASETYPE from the last virtual base class use
  283.      the right value for BASETYPE.  */
  284.   if (changed)
  285.     {
  286.       tree intype = TREE_TYPE (TREE_TYPE (expr));
  287.       if (TYPE_MAIN_VARIANT (intype) == BINFO_TYPE (last))
  288.     basetype = intype;
  289.       else
  290.     {
  291.       tree binfo = get_binfo (last, TYPE_MAIN_VARIANT (intype), 0);
  292.       basetype = last;
  293.       offset = BINFO_OFFSET (binfo);
  294.     }
  295.     }
  296.   else
  297.     {
  298.       if (last_virtual)
  299.     {
  300.       offset = BINFO_OFFSET (binfo_member (last_virtual,
  301.                            CLASSTYPE_VBASECLASSES (basetype)));
  302.       offset = size_binop (PLUS_EXPR, offset, BINFO_OFFSET (last));
  303.     }
  304.       else
  305.     offset = BINFO_OFFSET (last);
  306.     }
  307.  
  308.   if (TREE_INT_CST_LOW (offset))
  309.     {
  310.       /* Bash types to make the backend happy.  */
  311.       offset = convert (type, offset);
  312.       expr = build1 (NOP_EXPR, type, expr);
  313.  
  314.       /* For multiple inheritance: if `this' can be set by any
  315.      function, then it could be 0 on entry to any function.
  316.      Preserve such zeroness here.  Otherwise, only in the
  317.      case of constructors need we worry, and in those cases,
  318.      it will be zero, or initialized to some valid value to
  319.      which we may add.  */
  320.       if (nonnull == 0 && (alias_this == 0 || flag_this_is_variable > 0))
  321.     {
  322.       if (null_expr)
  323.         TREE_TYPE (null_expr) = type;
  324.       else
  325.         null_expr = build1 (NOP_EXPR, type, integer_zero_node);
  326.       if (TREE_SIDE_EFFECTS (expr))
  327.         expr = save_expr (expr);
  328.  
  329.       return build (COND_EXPR, type,
  330.             build (EQ_EXPR, boolean_type_node, expr, integer_zero_node),
  331.             null_expr,
  332.             build (code, type, expr, offset));
  333.     }
  334.       else return build (code, type, expr, offset);
  335.     }
  336.  
  337.   /* Cannot change the TREE_TYPE of a NOP_EXPR here, since it may
  338.      be used multiple times in initialization of multiple inheritance.  */
  339.   if (null_expr)
  340.     {
  341.       TREE_TYPE (expr) = type;
  342.       return expr;
  343.     }
  344.   else
  345.     return build1 (NOP_EXPR, type, expr);
  346. }
  347.  
  348. /* Virtual function things.  */
  349.  
  350. /* Virtual functions to be dealt with after laying out our base
  351.    classes.  We do all overrides after we layout virtual base classes.
  352.    */
  353. static tree pending_hard_virtuals;
  354. static int doing_hard_virtuals;
  355.  
  356. /* Build an entry in the virtual function table.
  357.    DELTA is the offset for the `this' pointer.
  358.    PFN is an ADDR_EXPR containing a pointer to the virtual function.
  359.    Note that the index (DELTA2) in the virtual function table
  360.    is always 0.  */
  361. tree
  362. build_vtable_entry (delta, pfn)
  363.      tree delta, pfn;
  364. {
  365.  
  366.   if (flag_vtable_thunks)
  367.     {
  368.       HOST_WIDE_INT idelta = TREE_INT_CST_LOW (delta);
  369.       extern tree make_thunk ();
  370.       if (idelta)
  371.     {
  372.       pfn = build1 (ADDR_EXPR, vtable_entry_type,
  373.             make_thunk (pfn, idelta));
  374.       TREE_READONLY (pfn) = 1;
  375.       TREE_CONSTANT (pfn) = 1;
  376.     }
  377. #ifdef GATHER_STATISTICS
  378.       n_vtable_entries += 1;
  379. #endif
  380.       return pfn;
  381.     }
  382.   else
  383.     {
  384.       extern int flag_huge_objects;
  385.       tree elems = tree_cons (NULL_TREE, delta,
  386.                   tree_cons (NULL_TREE, integer_zero_node,
  387.                      build_tree_list (NULL_TREE, pfn)));
  388.       tree entry = build (CONSTRUCTOR, vtable_entry_type, NULL_TREE, elems);
  389.  
  390.       /* DELTA is constructed by `size_int', which means it may be an
  391.      unsigned quantity on some platforms.  Therefore, we cannot use
  392.      `int_fits_type_p', because when DELTA is really negative,
  393.      `force_fit_type' will make it look like a very large number.  */
  394.  
  395.       if ((TREE_INT_CST_LOW (TYPE_MAX_VALUE (delta_type_node))
  396.        < TREE_INT_CST_LOW (delta))
  397.       || (TREE_INT_CST_LOW (delta)
  398.           < TREE_INT_CST_LOW (TYPE_MIN_VALUE (delta_type_node))))
  399.     if (flag_huge_objects)
  400.       sorry ("object size exceeds built-in limit for virtual function table implementation");
  401.     else
  402.       sorry ("object size exceeds normal limit for virtual function table implementation, recompile all source and use -fhuge-objects");
  403.  
  404.       TREE_CONSTANT (entry) = 1;
  405.       TREE_STATIC (entry) = 1;
  406.       TREE_READONLY (entry) = 1;
  407.  
  408. #ifdef GATHER_STATISTICS
  409.       n_vtable_entries += 1;
  410. #endif
  411.  
  412.       return entry;
  413.     }
  414. }
  415.  
  416. /* Given an object INSTANCE, return an expression which yields the
  417.    virtual function corresponding to INDEX.  There are many special
  418.    cases for INSTANCE which we take care of here, mainly to avoid
  419.    creating extra tree nodes when we don't have to.  */
  420. tree
  421. build_vfn_ref (ptr_to_instptr, instance, idx)
  422.      tree *ptr_to_instptr, instance;
  423.      tree idx;
  424. {
  425.   extern int building_cleanup;
  426.   tree vtbl, aref;
  427.   tree basetype = TREE_TYPE (instance);
  428.  
  429.   if (TREE_CODE (basetype) == REFERENCE_TYPE)
  430.     basetype = TREE_TYPE (basetype);
  431.  
  432.   if (instance == C_C_D)
  433.     vtbl = build_indirect_ref (build_vfield_ref (instance, basetype),
  434.                    NULL_PTR);
  435.   else
  436.     {
  437.       if (optimize)
  438.     {
  439.       /* Try to figure out what a reference refers to, and
  440.          access its virtual function table directly.  */
  441.       tree ref = NULL_TREE;
  442.  
  443.       if (TREE_CODE (instance) == INDIRECT_REF
  444.           && TREE_CODE (TREE_TYPE (TREE_OPERAND (instance, 0))) == REFERENCE_TYPE)
  445.         ref = TREE_OPERAND (instance, 0);
  446.       else if (TREE_CODE (TREE_TYPE (instance)) == REFERENCE_TYPE)
  447.         ref = instance;
  448.  
  449.       if (ref && TREE_CODE (ref) == VAR_DECL
  450.           && DECL_INITIAL (ref))
  451.         {
  452.           tree init = DECL_INITIAL (ref);
  453.  
  454.           while (TREE_CODE (init) == NOP_EXPR
  455.              || TREE_CODE (init) == NON_LVALUE_EXPR)
  456.         init = TREE_OPERAND (init, 0);
  457.           if (TREE_CODE (init) == ADDR_EXPR)
  458.         {
  459.           init = TREE_OPERAND (init, 0);
  460.           if (IS_AGGR_TYPE (TREE_TYPE (init))
  461.               && (TREE_CODE (init) == PARM_DECL
  462.               || TREE_CODE (init) == VAR_DECL))
  463.             instance = init;
  464.         }
  465.         }
  466.     }
  467.  
  468.       if (IS_AGGR_TYPE (TREE_TYPE (instance))
  469.       && !IS_SIGNATURE_POINTER (TREE_TYPE (instance))
  470.       && !IS_SIGNATURE_REFERENCE (TREE_TYPE (instance))
  471.       && (TREE_CODE (instance) == RESULT_DECL
  472.           || TREE_CODE (instance) == PARM_DECL
  473.           || TREE_CODE (instance) == VAR_DECL))
  474.     vtbl = TYPE_BINFO_VTABLE (basetype);
  475.       else
  476.     vtbl = build_indirect_ref (build_vfield_ref (instance, basetype),
  477.                    NULL_PTR);
  478.     }
  479.   assemble_external (vtbl);
  480.   aref = build_array_ref (vtbl, idx);
  481.  
  482.   /* Save the intermediate result in a SAVE_EXPR so we don't have to
  483.      compute each component of the virtual function pointer twice.  */ 
  484.   if (!building_cleanup && TREE_CODE (aref) == INDIRECT_REF)
  485.     TREE_OPERAND (aref, 0) = save_expr (TREE_OPERAND (aref, 0));
  486.  
  487.   if (flag_vtable_thunks)
  488.     return aref;
  489.   else
  490.     {
  491.       if (ptr_to_instptr)
  492.     *ptr_to_instptr
  493.       = build (PLUS_EXPR, TREE_TYPE (*ptr_to_instptr),
  494.            *ptr_to_instptr,
  495.            convert (ptrdiff_type_node,
  496.                 build_component_ref (aref, delta_identifier, 0, 0)));
  497.       return build_component_ref (aref, pfn_identifier, 0, 0);
  498.     }
  499. }
  500.  
  501. /* Return the name of the virtual function table (as an IDENTIFIER_NODE)
  502.    for the given TYPE.  */
  503. static tree
  504. get_vtable_name (type)
  505.      tree type;
  506. {
  507.   tree type_id = build_typename_overload (type);
  508.   char *buf = (char *)alloca (strlen (VTABLE_NAME_FORMAT)
  509.                   + IDENTIFIER_LENGTH (type_id) + 2);
  510.   char *ptr = IDENTIFIER_POINTER (type_id);
  511.   int i;
  512.   for (i = 0; ptr[i] == OPERATOR_TYPENAME_FORMAT[i]; i++) ;
  513. #if 0
  514.   /* We don't take off the numbers; prepare_fresh_vtable uses the
  515.      DECL_ASSEMBLER_NAME for the type, which includes the number
  516.      in `3foo'.  If we were to pull them off here, we'd end up with
  517.      something like `_vt.foo.3bar', instead of a uniform definition.  */
  518.   while (ptr[i] >= '0' && ptr[i] <= '9')
  519.     i += 1;
  520. #endif
  521.   sprintf (buf, VTABLE_NAME_FORMAT, ptr+i);
  522.   return get_identifier (buf);
  523. }
  524.  
  525. /* Build a virtual function for type TYPE.
  526.    If BINFO is non-NULL, build the vtable starting with the initial
  527.    approximation that it is the same as the one which is the head of
  528.    the association list.  */
  529. static tree
  530. build_vtable (binfo, type)
  531.      tree binfo, type;
  532. {
  533.   tree name = get_vtable_name (type);
  534.   tree virtuals, decl;
  535.  
  536.   if (binfo)
  537.     {
  538.       virtuals = copy_list (BINFO_VIRTUALS (binfo));
  539.       decl = build_decl (VAR_DECL, name, TREE_TYPE (BINFO_VTABLE (binfo)));
  540.     }
  541.   else
  542.     {
  543.       virtuals = NULL_TREE;
  544.       decl = build_decl (VAR_DECL, name, void_type_node);
  545.     }
  546.  
  547. #ifdef GATHER_STATISTICS
  548.   n_vtables += 1;
  549.   n_vtable_elems += list_length (virtuals);
  550. #endif
  551.  
  552.   /* Set TREE_PUBLIC and TREE_EXTERN as appropriate.  */
  553.   import_export_vtable (decl, type, 0);
  554.  
  555.   IDENTIFIER_GLOBAL_VALUE (name) = decl = pushdecl_top_level (decl);
  556.   /* Initialize the association list for this type, based
  557.      on our first approximation.  */
  558.   TYPE_BINFO_VTABLE (type) = decl;
  559.   TYPE_BINFO_VIRTUALS (type) = virtuals;
  560.  
  561.   TREE_STATIC (decl) = 1;
  562. #ifndef WRITABLE_VTABLES
  563.   /* Make them READONLY by default. (mrs) */
  564.   TREE_READONLY (decl) = 1;
  565. #endif
  566.   /* At one time the vtable info was grabbed 2 words at a time.  This
  567.      fails on sparc unless you have 8-byte alignment.  (tiemann) */
  568.   DECL_ALIGN (decl) = MAX (TYPE_ALIGN (double_type_node),
  569.                DECL_ALIGN (decl));
  570.  
  571.   /* Why is this conditional? (mrs) */
  572.   if (binfo && write_virtuals >= 0)
  573.     DECL_VIRTUAL_P (decl) = 1;
  574.   DECL_CONTEXT (decl) = type;
  575.  
  576.   binfo = TYPE_BINFO (type);
  577.   SET_BINFO_NEW_VTABLE_MARKED (binfo);
  578.   return decl;
  579. }
  580.  
  581. /* Given a base type PARENT, and a derived type TYPE, build
  582.    a name which distinguishes exactly the PARENT member of TYPE's type.
  583.  
  584.    FORMAT is a string which controls how sprintf formats the name
  585.    we have generated.
  586.  
  587.    For example, given
  588.  
  589.     class A; class B; class C : A, B;
  590.  
  591.    it is possible to distinguish "A" from "C's A".  And given
  592.  
  593.     class L;
  594.     class A : L; class B : L; class C : A, B;
  595.  
  596.    it is possible to distinguish "L" from "A's L", and also from
  597.    "C's L from A".
  598.  
  599.    Make sure to use the DECL_ASSEMBLER_NAME of the TYPE_NAME of the
  600.    type, as template have DECL_NAMEs like: X<int>, whereas the
  601.    DECL_ASSEMBLER_NAME is set to be something the assembler can handle.
  602.   */
  603. static tree
  604. build_type_pathname (format, parent, type)
  605.      char *format;
  606.      tree parent, type;
  607. {
  608.   extern struct obstack temporary_obstack;
  609.   char *first, *base, *name;
  610.   int i;
  611.   tree id;
  612.  
  613.   parent = TYPE_MAIN_VARIANT (parent);
  614.  
  615.   /* Remember where to cut the obstack to.  */
  616.   first = obstack_base (&temporary_obstack);
  617.  
  618.   /* Put on TYPE+PARENT.  */
  619.   obstack_grow (&temporary_obstack,
  620.         TYPE_ASSEMBLER_NAME_STRING (type),
  621.         TYPE_ASSEMBLER_NAME_LENGTH (type));
  622. #ifdef JOINER
  623.   obstack_1grow (&temporary_obstack, JOINER);
  624. #else
  625.   obstack_1grow (&temporary_obstack, '_');
  626. #endif
  627.   obstack_grow0 (&temporary_obstack,
  628.          TYPE_ASSEMBLER_NAME_STRING (parent),
  629.          TYPE_ASSEMBLER_NAME_LENGTH (parent));
  630.   i = obstack_object_size (&temporary_obstack);
  631.   base = obstack_base (&temporary_obstack);
  632.   obstack_finish (&temporary_obstack);
  633.  
  634.   /* Put on FORMAT+TYPE+PARENT.  */
  635.   obstack_blank (&temporary_obstack, strlen (format) + i + 1);
  636.   name = obstack_base (&temporary_obstack);
  637.   sprintf (name, format, base);
  638.   id = get_identifier (name);
  639.   obstack_free (&temporary_obstack, first);
  640.  
  641.   return id;
  642. }
  643.  
  644. /* Give TYPE a new virtual function table which is initialized
  645.    with a skeleton-copy of its original initialization.  The only
  646.    entry that changes is the `delta' entry, so we can really
  647.    share a lot of structure.
  648.  
  649.    FOR_TYPE is the derived type which caused this table to
  650.    be needed.
  651.  
  652.    BINFO is the type association which provided TYPE for FOR_TYPE.  */
  653. static void
  654. prepare_fresh_vtable (binfo, for_type)
  655.      tree binfo, for_type;
  656. {
  657.   tree basetype = BINFO_TYPE (binfo);
  658.   tree orig_decl = BINFO_VTABLE (binfo);
  659.   /* This name is too simplistic.  We can have multiple basetypes for
  660.      for_type, and we really want different names.  (mrs) */
  661.   tree name = build_type_pathname (VTABLE_NAME_FORMAT, basetype, for_type);
  662.   tree new_decl = build_decl (VAR_DECL, name, TREE_TYPE (orig_decl));
  663.   tree path, offset;
  664.   int result;
  665.  
  666.   /* Remember which class this vtable is really for.  */
  667.   DECL_CONTEXT (new_decl) = for_type;
  668.  
  669.   TREE_STATIC (new_decl) = 1;
  670.   BINFO_VTABLE (binfo) = pushdecl_top_level (new_decl);
  671.   DECL_VIRTUAL_P (new_decl) = 1;
  672. #ifndef WRITABLE_VTABLES
  673.   /* Make them READONLY by default. (mrs) */
  674.   TREE_READONLY (new_decl) = 1;
  675. #endif
  676.   DECL_ALIGN (new_decl) = DECL_ALIGN (orig_decl);
  677.  
  678.   /* Make fresh virtual list, so we can smash it later.  */
  679.   BINFO_VIRTUALS (binfo) = copy_list (BINFO_VIRTUALS (binfo));
  680.  
  681.   if (TREE_VIA_VIRTUAL (binfo))
  682.     offset = BINFO_OFFSET (binfo_member (BINFO_TYPE (binfo), 
  683.                 CLASSTYPE_VBASECLASSES (for_type)));
  684.   else
  685.     offset = BINFO_OFFSET (binfo);
  686.  
  687.   /* Install the value for `headof' if that's what we're doing.  */
  688.   if (flag_rtti)
  689.     TREE_VALUE (BINFO_VIRTUALS (binfo))
  690.       = build_vtable_entry (size_binop (MINUS_EXPR, integer_zero_node, offset),
  691.                 build_t_desc (for_type, 0));
  692.  
  693. #ifdef GATHER_STATISTICS
  694.   n_vtables += 1;
  695.   n_vtable_elems += list_length (BINFO_VIRTUALS (binfo));
  696. #endif
  697.  
  698.   /* Set TREE_PUBLIC and TREE_EXTERN as appropriate.  */
  699.   import_export_vtable (new_decl, for_type, 0);
  700.  
  701.   if (TREE_VIA_VIRTUAL (binfo))
  702.     my_friendly_assert (binfo == binfo_member (BINFO_TYPE (binfo),
  703.                    CLASSTYPE_VBASECLASSES (current_class_type)),
  704.             170);
  705.   SET_BINFO_NEW_VTABLE_MARKED (binfo);
  706. }
  707.  
  708. /* Access the virtual function table entry that logically
  709.    contains BASE_FNDECL.  VIRTUALS is the virtual function table's
  710.    initializer.  We can run off the end, when dealing with virtual
  711.    destructors in MI situations, return NULL_TREE in that case.  */
  712. static tree
  713. get_vtable_entry (virtuals, base_fndecl)
  714.      tree virtuals, base_fndecl;
  715. {
  716.   unsigned HOST_WIDE_INT i = (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD
  717.        ? (TREE_INT_CST_LOW (DECL_VINDEX (base_fndecl))
  718.           & (((unsigned HOST_WIDE_INT)1<<(BITS_PER_WORD-1))-1))
  719.        : TREE_INT_CST_LOW (DECL_VINDEX (base_fndecl)));
  720.  
  721. #ifdef GATHER_STATISTICS
  722.   n_vtable_searches += i;
  723. #endif
  724.  
  725.   while (i > 0 && virtuals)
  726.     {
  727.       virtuals = TREE_CHAIN (virtuals);
  728.       i -= 1;
  729.     }
  730.   return virtuals;
  731. }
  732.  
  733. /* Put new entry ENTRY into virtual function table initializer
  734.    VIRTUALS.
  735.  
  736.    Also update DECL_VINDEX (FNDECL).  */
  737.  
  738. static void
  739. modify_vtable_entry (old_entry_in_list, new_entry, fndecl)
  740.      tree old_entry_in_list, new_entry, fndecl;
  741. {
  742.   tree base_fndecl = TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (old_entry_in_list)), 0);
  743.  
  744. #ifdef NOTQUITE
  745.   cp_warning ("replaced %D with %D", DECL_ASSEMBLER_NAME (base_fndecl),
  746.           DECL_ASSEMBLER_NAME (fndecl));
  747. #endif
  748.   TREE_VALUE (old_entry_in_list) = new_entry;
  749.  
  750.   /* Now assign virtual dispatch information, if unset.  */
  751.   /* We can dispatch this, through any overridden base function. */
  752.   if (TREE_CODE (DECL_VINDEX (fndecl)) != INTEGER_CST)
  753.     {
  754.       DECL_VINDEX (fndecl) = DECL_VINDEX (base_fndecl);
  755.       DECL_CONTEXT (fndecl) = DECL_CONTEXT (base_fndecl);
  756.     }
  757. }
  758.  
  759. /* Access the virtual function table entry i.  VIRTUALS is the virtual
  760.    function table's initializer.  */
  761. static tree
  762. get_vtable_entry_n (virtuals, i)
  763.      tree virtuals;
  764.      unsigned HOST_WIDE_INT i;
  765. {
  766.   while (i > 0)
  767.     {
  768.       virtuals = TREE_CHAIN (virtuals);
  769.       i -= 1;
  770.     }
  771.   return virtuals;
  772. }
  773.  
  774. /* Add a virtual function to all the appropriate vtables for the class
  775.    T.  DECL_VINDEX(X) should be error_mark_node, if we want to
  776.    allocate a new slot in our table.  If it is error_mark_node, we
  777.    know that no other function from another vtable is overridden by X.
  778.    HAS_VIRTUAL keeps track of how many virtuals there are in our main
  779.    vtable for the type, and we build upon the PENDING_VIRTUALS list
  780.    and return it.  */
  781. static tree
  782. add_virtual_function (pending_virtuals, has_virtual, fndecl, t)
  783.      tree pending_virtuals;
  784.      int *has_virtual;
  785.      tree fndecl;
  786.      tree t; /* Structure type. */
  787. {
  788.   /* FUNCTION_TYPEs and OFFSET_TYPEs no longer freely
  789.      convert to void *.  Make such a conversion here.  */
  790.   tree vfn = build1 (ADDR_EXPR, vfunc_ptr_type_node, fndecl);
  791.   TREE_CONSTANT (vfn) = 1;
  792.  
  793. #ifndef DUMB_USER
  794.   if (current_class_type == 0)
  795.     cp_warning ("internal problem, current_class_type is zero when adding `%D', please report",
  796.         fndecl);
  797.   if (current_class_type && t != current_class_type)
  798.     cp_warning ("internal problem, current_class_type differs when adding `%D', please report",
  799.         fndecl);
  800. #endif
  801.  
  802.   /* If the virtual function is a redefinition of a prior one,
  803.      figure out in which base class the new definition goes,
  804.      and if necessary, make a fresh virtual function table
  805.      to hold that entry.  */
  806.   if (DECL_VINDEX (fndecl) == error_mark_node)
  807.     {
  808.       tree entry;
  809.  
  810.       if (flag_rtti && *has_virtual == 0)
  811.     {
  812.       /* CLASSTYPE_RTTI is only used as a Boolean (NULL or not). */
  813.       CLASSTYPE_RTTI (t) = integer_one_node;
  814. #if 0
  815.       *has_virtual = 1;
  816. #endif
  817.         }
  818.  
  819.       /* Build a new INT_CST for this DECL_VINDEX.  */
  820.       {
  821.     static tree index_table[256];
  822.     tree index;
  823.     int i = ++(*has_virtual);
  824.  
  825.     if (i >= 256 || index_table[i] == 0)
  826.       {
  827.         index = build_int_2 (i, 0);
  828.         if (i < 256)
  829.           index_table[i] = index;
  830.       }
  831.     else
  832.       index = index_table[i];
  833.  
  834.     /* Now assign virtual dispatch information. */
  835.     DECL_VINDEX (fndecl) = index;
  836.     DECL_CONTEXT (fndecl) = t;
  837.       }
  838.       entry = build_vtable_entry (integer_zero_node, vfn);
  839.       pending_virtuals = tree_cons (DECL_VINDEX (fndecl), entry, pending_virtuals);
  840.     }
  841.   /* Might already be INTEGER_CST if declared twice in class.  We will
  842.      give error later or we've already given it.  */
  843.   else if (TREE_CODE (DECL_VINDEX (fndecl)) != INTEGER_CST)
  844.     {
  845.       /* Need an entry in some other virtual function table.
  846.          Deal with this after we have laid out our virtual base classes.  */
  847.       pending_hard_virtuals = temp_tree_cons (fndecl, vfn, pending_hard_virtuals);
  848.     }
  849.   return pending_virtuals;
  850. }
  851.  
  852. /* Obstack on which to build the vector of class methods.  */
  853. struct obstack class_obstack;
  854. extern struct obstack *current_obstack;
  855.  
  856. /* Add method METHOD to class TYPE.  This is used when a method
  857.    has been defined which did not initially appear in the class definition,
  858.    and helps cut down on spurious error messages.
  859.  
  860.    FIELDS is the entry in the METHOD_VEC vector entry of the class type where
  861.    the method should be added.  */
  862. void
  863. add_method (type, fields, method)
  864.      tree type, *fields, method;
  865. {
  866.   /* We must make a copy of METHOD here, since we must be sure that
  867.      we have exclusive title to this method's DECL_CHAIN.  */
  868.   tree decl;
  869.  
  870.   push_obstacks (&permanent_obstack, &permanent_obstack);
  871.   {
  872.     decl = copy_node (method);
  873.     if (DECL_RTL (decl) == 0
  874.         && (!processing_template_decl
  875.             || !uses_template_parms (decl)))
  876.       {
  877.     make_function_rtl (decl);
  878.     DECL_RTL (method) = DECL_RTL (decl);
  879.       }
  880.   }
  881.  
  882.   if (fields && *fields)
  883.     {
  884.       /* Take care not to hide destructor.  */
  885.       DECL_CHAIN (decl) = DECL_CHAIN (*fields);
  886.       DECL_CHAIN (*fields) = decl;
  887.     }
  888.   else if (CLASSTYPE_METHOD_VEC (type) == 0)
  889.     {
  890.       tree method_vec = make_node (TREE_VEC);
  891.       if (TYPE_IDENTIFIER (type) == DECL_NAME (decl))
  892.     {
  893.       TREE_VEC_ELT (method_vec, 0) = decl;
  894.       TREE_VEC_LENGTH (method_vec) = 1;
  895.     }
  896.       else
  897.     {
  898.       /* ??? Is it possible for there to have been enough room in the
  899.          current chunk for the tree_vec structure but not a tree_vec
  900.          plus a tree*?  Will this work in that case?  */
  901.       obstack_free (current_obstack, method_vec);
  902.       obstack_blank (current_obstack, sizeof (struct tree_vec) + sizeof (tree *));
  903.       TREE_VEC_ELT (method_vec, 1) = decl;
  904.       TREE_VEC_LENGTH (method_vec) = 2;
  905.       obstack_finish (current_obstack);
  906.     }
  907.       CLASSTYPE_METHOD_VEC (type) = method_vec;
  908.     }
  909.   else
  910.     {
  911.       tree method_vec = CLASSTYPE_METHOD_VEC (type);
  912.       int len = TREE_VEC_LENGTH (method_vec);
  913.  
  914.       /* Adding a new ctor or dtor.  This is easy because our
  915.          METHOD_VEC always has a slot for such entries.  */
  916.       if (TYPE_IDENTIFIER (type) == DECL_NAME (decl))
  917.     {
  918.       /* TREE_VEC_ELT (method_vec, 0) = decl; */
  919.       if (decl != TREE_VEC_ELT (method_vec, 0))
  920.         {
  921.           DECL_CHAIN (decl) = TREE_VEC_ELT (method_vec, 0);
  922.           TREE_VEC_ELT (method_vec, 0) = decl;
  923.         }
  924.     }
  925.       else
  926.     {
  927.       /* This is trickier.  We try to extend the TREE_VEC in-place,
  928.          but if that does not work, we copy all its data to a new
  929.          TREE_VEC that's large enough.  */
  930.       struct obstack *ob = &class_obstack;
  931.       tree *end = (tree *)obstack_next_free (ob);
  932.  
  933.       if (end != TREE_VEC_END (method_vec))
  934.         {
  935.           ob = current_obstack;
  936.           TREE_VEC_LENGTH (method_vec) += 1;
  937.           TREE_VEC_ELT (method_vec, len) = NULL_TREE;
  938.           method_vec = copy_node (method_vec);
  939.           TREE_VEC_LENGTH (method_vec) -= 1;
  940.         }
  941.       else
  942.         {
  943.           tree tmp_vec = (tree) obstack_base (ob);
  944.           if (obstack_room (ob) < sizeof (tree))
  945.         {
  946.           obstack_blank (ob, sizeof (struct tree_common)
  947.                  + tree_code_length[(int) TREE_VEC]
  948.                    * sizeof (char *)
  949.                  + len * sizeof (tree));
  950.           tmp_vec = (tree) obstack_base (ob);
  951.           bcopy ((char *) method_vec, (char *) tmp_vec,
  952.              (sizeof (struct tree_common)
  953.               + tree_code_length[(int) TREE_VEC] * sizeof (char *)
  954.               + (len-1) * sizeof (tree)));
  955.           method_vec = tmp_vec;
  956.         }
  957.           else
  958.         obstack_blank (ob, sizeof (tree));
  959.         }
  960.  
  961.       obstack_finish (ob);
  962.       TREE_VEC_ELT (method_vec, len) = decl;
  963.       TREE_VEC_LENGTH (method_vec) = len + 1;
  964.       CLASSTYPE_METHOD_VEC (type) = method_vec;
  965.  
  966.       if (TYPE_BINFO_BASETYPES (type) && CLASSTYPE_BASELINK_VEC (type))
  967.         {
  968.           /* ??? May be better to know whether these can be extended?  */
  969.           tree baselink_vec = CLASSTYPE_BASELINK_VEC (type);
  970.  
  971.           TREE_VEC_LENGTH (baselink_vec) += 1;
  972.           CLASSTYPE_BASELINK_VEC (type) = copy_node (baselink_vec);
  973.           TREE_VEC_LENGTH (baselink_vec) -= 1;
  974.  
  975.           TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type), len) = 0;
  976.         }
  977.     }
  978.     }
  979.   DECL_CONTEXT (decl) = type;
  980.   DECL_CLASS_CONTEXT (decl) = type;
  981.  
  982.   pop_obstacks ();
  983. }
  984.  
  985. /* Subroutines of finish_struct.  */
  986.  
  987. /* Look through the list of fields for this struct, deleting
  988.    duplicates as we go.  This must be recursive to handle
  989.    anonymous unions.
  990.  
  991.    FIELD is the field which may not appear anywhere in FIELDS.
  992.    FIELD_PTR, if non-null, is the starting point at which
  993.    chained deletions may take place.
  994.    The value returned is the first acceptable entry found
  995.    in FIELDS.
  996.  
  997.    Note that anonymous fields which are not of UNION_TYPE are
  998.    not duplicates, they are just anonymous fields.  This happens
  999.    when we have unnamed bitfields, for example.  */
  1000. static tree
  1001. delete_duplicate_fields_1 (field, fields)
  1002.      tree field, fields;
  1003. {
  1004.   tree x;
  1005.   tree prev = 0;
  1006.   if (DECL_NAME (field) == 0)
  1007.     {
  1008.       if (TREE_CODE (TREE_TYPE (field)) != UNION_TYPE)
  1009.     return fields;
  1010.  
  1011.       for (x = TYPE_FIELDS (TREE_TYPE (field)); x; x = TREE_CHAIN (x))
  1012.     fields = delete_duplicate_fields_1 (x, fields);
  1013.       return fields;
  1014.     }
  1015.   else
  1016.     {
  1017.       for (x = fields; x; prev = x, x = TREE_CHAIN (x))
  1018.     {
  1019.       if (DECL_NAME (x) == 0)
  1020.         {
  1021.           if (TREE_CODE (TREE_TYPE (x)) != UNION_TYPE)
  1022.         continue;
  1023.           TYPE_FIELDS (TREE_TYPE (x))
  1024.         = delete_duplicate_fields_1 (field, TYPE_FIELDS (TREE_TYPE (x)));
  1025.           if (TYPE_FIELDS (TREE_TYPE (x)) == 0)
  1026.         {
  1027.           if (prev == 0)
  1028.             fields = TREE_CHAIN (fields);
  1029.           else
  1030.             TREE_CHAIN (prev) = TREE_CHAIN (x);
  1031.         }
  1032.         }
  1033.       else
  1034.         {
  1035.           if (DECL_NAME (field) == DECL_NAME (x))
  1036.         {
  1037.           if (TREE_CODE (field) == CONST_DECL
  1038.               && TREE_CODE (x) == CONST_DECL)
  1039.             cp_error_at ("duplicate enum value `%D'", x);
  1040.           else if (TREE_CODE (field) == CONST_DECL
  1041.                || TREE_CODE (x) == CONST_DECL)
  1042.             cp_error_at ("duplicate field `%D' (as enum and non-enum)",
  1043.                 x);
  1044.           else if (TREE_CODE (field) == TYPE_DECL
  1045.                && TREE_CODE (x) == TYPE_DECL)
  1046.             cp_error_at ("duplicate nested type `%D'", x);
  1047.           else if (TREE_CODE (field) == TYPE_DECL
  1048.                || TREE_CODE (x) == TYPE_DECL)
  1049.             cp_error_at ("duplicate field `%D' (as type and non-type)",
  1050.                 x);
  1051.           else
  1052.             cp_error_at ("duplicate member `%D'", x);
  1053.           if (prev == 0)
  1054.             fields = TREE_CHAIN (fields);
  1055.           else
  1056.             TREE_CHAIN (prev) = TREE_CHAIN (x);
  1057.         }
  1058.         }
  1059.     }
  1060.     }
  1061.   return fields;
  1062. }
  1063.  
  1064. static void
  1065. delete_duplicate_fields (fields)
  1066.      tree fields;
  1067. {
  1068.   tree x;
  1069.   for (x = fields; x && TREE_CHAIN (x); x = TREE_CHAIN (x))
  1070.     TREE_CHAIN (x) = delete_duplicate_fields_1 (x, TREE_CHAIN (x));
  1071. }
  1072.  
  1073. /* Change the access of FDECL to ACCESS in T.
  1074.    Return 1 if change was legit, otherwise return 0.  */
  1075. static int
  1076. alter_access (t, fdecl, access)
  1077.      tree t;
  1078.      tree fdecl;
  1079.      enum access_type access;
  1080. {
  1081.   tree elem = purpose_member (t, DECL_ACCESS (fdecl));
  1082.   if (elem && TREE_VALUE (elem) != (tree)access)
  1083.     {
  1084.       if (TREE_CODE (TREE_TYPE (fdecl)) == FUNCTION_DECL)
  1085.     {
  1086.       cp_error_at ("conflicting access specifications for method `%D', ignored", TREE_TYPE (fdecl));
  1087.     }
  1088.       else
  1089.     error ("conflicting access specifications for field `%s', ignored",
  1090.            IDENTIFIER_POINTER (DECL_NAME (fdecl)));
  1091.     }
  1092.   else if (TREE_PRIVATE (fdecl))
  1093.     {
  1094.       if (access != access_private)
  1095.     cp_error_at ("cannot make private `%D' non-private", fdecl);
  1096.       goto alter;
  1097.     }
  1098.   else if (TREE_PROTECTED (fdecl))
  1099.     {
  1100.       if (access != access_protected)
  1101.     cp_error_at ("cannot make protected `%D' non-protected", fdecl);
  1102.       goto alter;
  1103.     }
  1104.   /* ARM 11.3: an access declaration may not be used to restrict access
  1105.      to a member that is accessible in the base class.  */
  1106.   else if (access != access_public)
  1107.     cp_error_at ("cannot reduce access of public member `%D'", fdecl);
  1108.   else if (elem == NULL_TREE)
  1109.     {
  1110.     alter:
  1111.       DECL_ACCESS (fdecl) = tree_cons (t, (tree)access,
  1112.                        DECL_ACCESS (fdecl));
  1113.       return 1;
  1114.     }
  1115.   return 0;
  1116. }
  1117.  
  1118. /* Return the offset to the main vtable for a given base BINFO.  */
  1119. tree
  1120. get_vfield_offset (binfo)
  1121.      tree binfo;
  1122. {
  1123.   return size_binop (PLUS_EXPR,
  1124.              size_binop (FLOOR_DIV_EXPR,
  1125.                  DECL_FIELD_BITPOS (CLASSTYPE_VFIELD (BINFO_TYPE (binfo))),
  1126.                  size_int (BITS_PER_UNIT)),
  1127.              BINFO_OFFSET (binfo));
  1128. }
  1129.  
  1130. /* Get the offset to the start of the original binfo that we derived
  1131.    this binfo from.  If we find TYPE first, return the offset only
  1132.    that far.  The shortened search is useful because the this pointer
  1133.    on method calling is expected to point to a DECL_CONTEXT (fndecl)
  1134.    object, and not a baseclass of it.  */
  1135. static tree
  1136. get_derived_offset (binfo, type)
  1137.      tree binfo, type;
  1138. {
  1139.   tree offset1 = get_vfield_offset (TYPE_BINFO (BINFO_TYPE (binfo)));
  1140.   tree offset2;
  1141.   int i;
  1142.   while (BINFO_BASETYPES (binfo)
  1143.      && (i=CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo))) != -1)
  1144.     {
  1145.       tree binfos = BINFO_BASETYPES (binfo);
  1146.       if (BINFO_TYPE (binfo) == type)
  1147.     break;
  1148.       binfo = TREE_VEC_ELT (binfos, i);
  1149.     }
  1150.   offset2 = get_vfield_offset (TYPE_BINFO (BINFO_TYPE (binfo)));
  1151.   return size_binop (MINUS_EXPR, offset1, offset2);
  1152. }
  1153.  
  1154. /* If FOR_TYPE needs to reinitialize virtual function table pointers
  1155.    for TYPE's sub-objects, add such reinitializations to BASE_INIT_LIST.
  1156.    Returns BASE_INIT_LIST appropriately modified.  */
  1157.  
  1158. static tree
  1159. maybe_fixup_vptrs (for_type, binfo, base_init_list)
  1160.      tree for_type, binfo, base_init_list;
  1161. {
  1162.   /* Now reinitialize any slots that don't fall under our virtual
  1163.      function table pointer.  */
  1164.   tree vfields = CLASSTYPE_VFIELDS (BINFO_TYPE (binfo));
  1165.   while (vfields)
  1166.     {
  1167.       tree basetype = VF_NORMAL_VALUE (vfields)
  1168.     ? TYPE_MAIN_VARIANT (VF_NORMAL_VALUE (vfields))
  1169.       : VF_BASETYPE_VALUE (vfields);
  1170.  
  1171.       tree base_binfo = get_binfo (basetype, for_type, 0);
  1172.       /* Punt until this is implemented. */
  1173.       if (1 /* BINFO_MODIFIED (base_binfo) */)
  1174.     {
  1175.       tree base_offset = get_vfield_offset (base_binfo);
  1176.       if (! tree_int_cst_equal (base_offset, get_vfield_offset (TYPE_BINFO (for_type)))
  1177.           && ! tree_int_cst_equal (base_offset, get_vfield_offset (binfo)))
  1178.         base_init_list = tree_cons (error_mark_node, base_binfo,
  1179.                     base_init_list);
  1180.     }
  1181.       vfields = TREE_CHAIN (vfields);
  1182.     }
  1183.   return base_init_list;
  1184. }
  1185.  
  1186. /* If TYPE does not have a constructor, then the compiler must
  1187.    manually deal with all of the initialization this type requires.
  1188.  
  1189.    If a base initializer exists only to fill in the virtual function
  1190.    table pointer, then we mark that fact with the TREE_VIRTUAL bit.
  1191.    This way, we avoid multiple initializations of the same field by
  1192.    each virtual function table up the class hierarchy.
  1193.  
  1194.    Virtual base class pointers are not initialized here.  They are
  1195.    initialized only at the "top level" of object creation.  If we
  1196.    initialized them here, we would have to skip a lot of work.  */
  1197.  
  1198. static void
  1199. build_class_init_list (type)
  1200.      tree type;
  1201. {
  1202.   tree base_init_list = NULL_TREE;
  1203.   tree member_init_list = NULL_TREE;
  1204.  
  1205.   /* Since we build member_init_list and base_init_list using
  1206.      tree_cons, backwards fields the all through work.  */
  1207.   tree x;
  1208.   tree binfos = BINFO_BASETYPES (TYPE_BINFO (type));
  1209.   int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
  1210.  
  1211.   for (x = TYPE_FIELDS (type); x; x = TREE_CHAIN (x))
  1212.     {
  1213.       if (TREE_CODE (x) != FIELD_DECL)
  1214.     continue;
  1215.  
  1216.       if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (x))
  1217.       || DECL_INITIAL (x) != NULL_TREE)
  1218.     member_init_list = tree_cons (x, type, member_init_list);
  1219.     }
  1220.   member_init_list = nreverse (member_init_list);
  1221.  
  1222.   /* We will end up doing this last.  Need special marker
  1223.      to avoid infinite regress.  */
  1224.   if (TYPE_VIRTUAL_P (type))
  1225.     {
  1226.       base_init_list = build_tree_list (error_mark_node, TYPE_BINFO (type));
  1227.       if (CLASSTYPE_NEEDS_VIRTUAL_REINIT (type) == 0)
  1228.     TREE_VALUE (base_init_list) = NULL_TREE;
  1229.       TREE_ADDRESSABLE (base_init_list) = 1;
  1230.     }
  1231.  
  1232.   /* Each base class which needs to have initialization
  1233.      of some kind gets to make such requests known here.  */
  1234.   for (i = n_baseclasses-1; i >= 0; i--)
  1235.     {
  1236.       tree base_binfo = TREE_VEC_ELT (binfos, i);
  1237.       tree blist;
  1238.  
  1239.       /* Don't initialize virtual baseclasses this way.  */
  1240.       if (TREE_VIA_VIRTUAL (base_binfo))
  1241.     continue;
  1242.  
  1243.       if (TYPE_HAS_CONSTRUCTOR (BINFO_TYPE (base_binfo)))
  1244.     {
  1245.       /* ...and the last shall come first...  */
  1246.       base_init_list = maybe_fixup_vptrs (type, base_binfo, base_init_list);
  1247.       base_init_list = tree_cons (NULL_TREE, base_binfo, base_init_list);
  1248.       continue;
  1249.     }
  1250.  
  1251.       if ((blist = CLASSTYPE_BASE_INIT_LIST (BINFO_TYPE (base_binfo))) == NULL_TREE)
  1252.     /* Nothing to initialize.  */
  1253.     continue;
  1254.  
  1255.       /* ...ditto...  */
  1256.       base_init_list = maybe_fixup_vptrs (type, base_binfo, base_init_list);
  1257.  
  1258.       /* This is normally true for single inheritance.
  1259.      The win is we can shrink the chain of initializations
  1260.      to be done by only converting to the actual type
  1261.      we are interested in.  */
  1262.       if (TREE_VALUE (blist)
  1263.       && TREE_CODE (TREE_VALUE (blist)) == TREE_VEC
  1264.       && tree_int_cst_equal (BINFO_OFFSET (base_binfo),
  1265.                  BINFO_OFFSET (TREE_VALUE (blist))))
  1266.     {
  1267.       if (base_init_list)
  1268.         {
  1269.           /* Does it do more than just fill in a
  1270.          virtual function table pointer?  */
  1271.           if (! TREE_ADDRESSABLE (blist))
  1272.         base_init_list = build_tree_list (blist, base_init_list);
  1273.           /* Can we get by just with the virtual function table
  1274.          pointer that it fills in?  */
  1275.           else if (TREE_ADDRESSABLE (base_init_list)
  1276.                && TREE_VALUE (base_init_list) == 0)
  1277.         base_init_list = blist;
  1278.           /* Maybe, but it is not obvious as the previous case.  */
  1279.           else if (! CLASSTYPE_NEEDS_VIRTUAL_REINIT (type))
  1280.         {
  1281.           tree last = tree_last (base_init_list);
  1282.           while (TREE_VALUE (last)
  1283.              && TREE_CODE (TREE_VALUE (last)) == TREE_LIST)
  1284.             last = tree_last (TREE_VALUE (last));
  1285.           if (TREE_VALUE (last) == 0)
  1286.             base_init_list = build_tree_list (blist, base_init_list);
  1287.         }
  1288.         }
  1289.       else
  1290.         base_init_list = blist;
  1291.     }
  1292.       else
  1293.     {
  1294.       /* The function expand_aggr_init knows how to do the
  1295.          initialization of `basetype' without getting
  1296.          an explicit `blist'.  */
  1297.       if (base_init_list)
  1298.         base_init_list = tree_cons (NULL_TREE, base_binfo, base_init_list);
  1299.       else
  1300.         base_init_list = CLASSTYPE_BINFO_AS_LIST (BINFO_TYPE (base_binfo));
  1301.     }
  1302.     }
  1303.  
  1304.   if (base_init_list)
  1305.     if (member_init_list)
  1306.       CLASSTYPE_BASE_INIT_LIST (type) = build_tree_list (base_init_list, member_init_list);
  1307.     else
  1308.       CLASSTYPE_BASE_INIT_LIST (type) = base_init_list;
  1309.   else if (member_init_list)
  1310.     CLASSTYPE_BASE_INIT_LIST (type) = member_init_list;
  1311. }
  1312.  
  1313. struct base_info
  1314. {
  1315.   int has_virtual;
  1316.   int max_has_virtual;
  1317.   int n_ancestors;
  1318.   tree vfield;
  1319.   tree vfields;
  1320.   char cant_have_default_ctor;
  1321.   char cant_have_const_ctor;
  1322.   char cant_synth_copy_ctor;
  1323.   char cant_synth_asn_ref;
  1324.   char no_const_asn_ref;
  1325.   char needs_virtual_dtor;
  1326. };
  1327.  
  1328. /* Record information about type T derived from its base classes.
  1329.    Store most of that information in T itself, and place the
  1330.    remaining information in the struct BASE_INFO.
  1331.  
  1332.    Propagate basetype offsets throughout the lattice.  Note that the
  1333.    lattice topped by T is really a pair: it's a DAG that gives the
  1334.    structure of the derivation hierarchy, and it's a list of the
  1335.    virtual baseclasses that appear anywhere in the DAG.  When a vbase
  1336.    type appears in the DAG, it's offset is 0, and it's children start
  1337.    their offsets from that point.  When a vbase type appears in the list,
  1338.    its offset is the offset it has in the hierarchy, and its children's
  1339.    offsets include that offset in theirs.
  1340.  
  1341.    Returns the index of the first base class to have virtual functions,
  1342.    or -1 if no such base class.
  1343.  
  1344.    Note that at this point TYPE_BINFO (t) != t_binfo.  */
  1345.  
  1346. static int
  1347. finish_base_struct (t, b, t_binfo)
  1348.      tree t;
  1349.      struct base_info *b;
  1350.      tree t_binfo;
  1351. {
  1352.   tree binfos = BINFO_BASETYPES (t_binfo);
  1353.   int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
  1354.   int first_vfn_base_index = -1;
  1355.   bzero ((char *) b, sizeof (struct base_info));
  1356.  
  1357.   for (i = 0; i < n_baseclasses; i++)
  1358.     {
  1359.       tree base_binfo = TREE_VEC_ELT (binfos, i);
  1360.       tree basetype = BINFO_TYPE (base_binfo);
  1361.  
  1362.       /* If the type of basetype is incomplete, then
  1363.      we already complained about that fact
  1364.      (and we should have fixed it up as well).  */
  1365.       if (TYPE_SIZE (basetype) == 0)
  1366.     {
  1367.       int j;
  1368.       /* The base type is of incomplete type.  It is
  1369.          probably best to pretend that it does not
  1370.          exist.  */
  1371.       if (i == n_baseclasses-1)
  1372.         TREE_VEC_ELT (binfos, i) = NULL_TREE;
  1373.       TREE_VEC_LENGTH (binfos) -= 1;
  1374.       n_baseclasses -= 1;
  1375.       for (j = i; j+1 < n_baseclasses; j++)
  1376.         TREE_VEC_ELT (binfos, j) = TREE_VEC_ELT (binfos, j+1);
  1377.     }
  1378.  
  1379.       if (TYPE_HAS_INIT_REF (basetype)
  1380.       && !TYPE_HAS_CONST_INIT_REF (basetype))
  1381.     b->cant_have_const_ctor = 1;
  1382.       if (! TYPE_HAS_INIT_REF (basetype)
  1383.       || (TYPE_HAS_NONPUBLIC_CTOR (basetype) == 2
  1384.           && ! is_friend_type (t, basetype)))
  1385.     b->cant_synth_copy_ctor = 1;
  1386.  
  1387.       if (TYPE_HAS_CONSTRUCTOR (basetype)
  1388.       && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype))
  1389.     {
  1390.       b->cant_have_default_ctor = 1;
  1391.       if (! TYPE_HAS_CONSTRUCTOR (t))
  1392.         {
  1393.           cp_pedwarn ("base `%T' with only non-default constructor",
  1394.               basetype);
  1395.           cp_pedwarn ("in class without a constructor");
  1396.         }
  1397.     }
  1398.  
  1399.       if (TYPE_HAS_ASSIGN_REF (basetype)
  1400.       && !TYPE_HAS_CONST_ASSIGN_REF (basetype))
  1401.     b->no_const_asn_ref = 1;
  1402.       if (! TYPE_HAS_ASSIGN_REF (basetype)
  1403.       || TYPE_HAS_ABSTRACT_ASSIGN_REF (basetype)
  1404.       || (TYPE_HAS_NONPUBLIC_ASSIGN_REF (basetype) == 2
  1405.           && ! is_friend_type (t, basetype)))
  1406.     b->cant_synth_asn_ref = 1;
  1407.  
  1408.       b->n_ancestors += CLASSTYPE_N_SUPERCLASSES (basetype);
  1409.       TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (basetype);
  1410.       TYPE_NEEDS_DESTRUCTOR (t) |= TYPE_NEEDS_DESTRUCTOR (basetype);
  1411.       TYPE_HAS_COMPLEX_ASSIGN_REF (t) |= TYPE_HAS_COMPLEX_ASSIGN_REF (basetype);
  1412.       TYPE_HAS_COMPLEX_INIT_REF (t) |= TYPE_HAS_COMPLEX_INIT_REF (basetype);
  1413.  
  1414.       TYPE_OVERLOADS_CALL_EXPR (t) |= TYPE_OVERLOADS_CALL_EXPR (basetype);
  1415.       TYPE_OVERLOADS_ARRAY_REF (t) |= TYPE_OVERLOADS_ARRAY_REF (basetype);
  1416.       TYPE_OVERLOADS_ARROW (t) |= TYPE_OVERLOADS_ARROW (basetype);
  1417.  
  1418.       if (! TREE_VIA_VIRTUAL (base_binfo)
  1419. #if 0
  1420.       /* This cannot be done, as prepare_fresh_vtable wants to modify
  1421.          binfos associated with vfields anywhere in the hierarchy, not
  1422.          just immediate base classes.  Due to unsharing, the compiler
  1423.          might consume 3% more memory on a real program.
  1424.          */
  1425.       && ! BINFO_OFFSET_ZEROP (base_binfo)
  1426. #endif
  1427.       && BINFO_BASETYPES (base_binfo))
  1428.     {
  1429.       tree base_binfos = BINFO_BASETYPES (base_binfo);
  1430.       tree chain = NULL_TREE;
  1431.       int j;
  1432.  
  1433.       /* Now unshare the structure beneath BASE_BINFO.  */
  1434.       for (j = TREE_VEC_LENGTH (base_binfos)-1;
  1435.            j >= 0; j--)
  1436.         {
  1437.           tree base_base_binfo = TREE_VEC_ELT (base_binfos, j);
  1438.           if (! TREE_VIA_VIRTUAL (base_base_binfo))
  1439.         TREE_VEC_ELT (base_binfos, j)
  1440.           = make_binfo (BINFO_OFFSET (base_base_binfo),
  1441.                 base_base_binfo,
  1442.                 BINFO_VTABLE (base_base_binfo),
  1443.                 BINFO_VIRTUALS (base_base_binfo),
  1444.                 chain);
  1445.           chain = TREE_VEC_ELT (base_binfos, j);
  1446.           TREE_VIA_PUBLIC (chain) = TREE_VIA_PUBLIC (base_base_binfo);
  1447.           TREE_VIA_PROTECTED (chain) = TREE_VIA_PROTECTED (base_base_binfo);
  1448.           BINFO_INHERITANCE_CHAIN (chain) = base_binfo;
  1449.         }
  1450.  
  1451.       /* Completely unshare potentially shared data, and
  1452.          update what is ours.  */
  1453.       propagate_binfo_offsets (base_binfo, BINFO_OFFSET (base_binfo));
  1454.     }
  1455.  
  1456.       if (! TREE_VIA_VIRTUAL (base_binfo))
  1457.     CLASSTYPE_N_SUPERCLASSES (t) += 1;
  1458.  
  1459.       if (TYPE_VIRTUAL_P (basetype))
  1460.     {
  1461.       /* If there's going to be a destructor needed, make
  1462.          sure it will be virtual.  */
  1463.       b->needs_virtual_dtor = 1;
  1464.  
  1465.       /* Don't borrow virtuals from virtual baseclasses.  */
  1466.       if (TREE_VIA_VIRTUAL (base_binfo))
  1467.         continue;
  1468.  
  1469.       if (first_vfn_base_index < 0)
  1470.         {
  1471.           tree vfields;
  1472.           first_vfn_base_index = i;
  1473.  
  1474.           /* Update these two, now that we know what vtable we are
  1475.          going to extend.  This is so that we can add virtual
  1476.          functions, and override them properly.  */
  1477.           BINFO_VTABLE (t_binfo) = TYPE_BINFO_VTABLE (basetype);
  1478.           BINFO_VIRTUALS (t_binfo) = TYPE_BINFO_VIRTUALS (basetype);
  1479.           b->has_virtual = CLASSTYPE_VSIZE (basetype);
  1480.           b->vfield = CLASSTYPE_VFIELD (basetype);
  1481.           b->vfields = copy_list (CLASSTYPE_VFIELDS (basetype));
  1482.           vfields = b->vfields;
  1483.           while (vfields)
  1484.         {
  1485.           if (VF_BINFO_VALUE (vfields) == NULL_TREE
  1486.               || ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields)))
  1487.             {
  1488.               tree value = VF_BASETYPE_VALUE (vfields);
  1489.               if (DECL_NAME (CLASSTYPE_VFIELD (value))
  1490.               == DECL_NAME (CLASSTYPE_VFIELD (basetype)))
  1491.             VF_NORMAL_VALUE (b->vfields) = basetype;
  1492.               else
  1493.             VF_NORMAL_VALUE (b->vfields) = VF_NORMAL_VALUE (vfields);
  1494.             }
  1495.           vfields = TREE_CHAIN (vfields);
  1496.         }
  1497.           CLASSTYPE_VFIELD (t) = b->vfield;
  1498.         }
  1499.       else
  1500.         {
  1501.           /* Only add unique vfields, and flatten them out as we go.  */
  1502.           tree vfields = CLASSTYPE_VFIELDS (basetype);
  1503.           while (vfields)
  1504.         {
  1505.           if (VF_BINFO_VALUE (vfields) == NULL_TREE
  1506.               || ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields)))
  1507.             {
  1508.               tree value = VF_BASETYPE_VALUE (vfields);
  1509.               b->vfields = tree_cons (base_binfo, value, b->vfields);
  1510.               if (DECL_NAME (CLASSTYPE_VFIELD (value))
  1511.               == DECL_NAME (CLASSTYPE_VFIELD (basetype)))
  1512.             VF_NORMAL_VALUE (b->vfields) = basetype;
  1513.               else
  1514.             VF_NORMAL_VALUE (b->vfields) = VF_NORMAL_VALUE (vfields);
  1515.             }
  1516.           vfields = TREE_CHAIN (vfields);
  1517.         }
  1518.  
  1519.           if (b->has_virtual == 0)
  1520.         {
  1521.           first_vfn_base_index = i;
  1522.  
  1523.           /* Update these two, now that we know what vtable we are
  1524.              going to extend.  This is so that we can add virtual
  1525.              functions, and override them properly.  */
  1526.           BINFO_VTABLE (t_binfo) = TYPE_BINFO_VTABLE (basetype);
  1527.           BINFO_VIRTUALS (t_binfo) = TYPE_BINFO_VIRTUALS (basetype);
  1528.           b->has_virtual = CLASSTYPE_VSIZE (basetype);
  1529.           b->vfield = CLASSTYPE_VFIELD (basetype);
  1530.           CLASSTYPE_VFIELD (t) = b->vfield;
  1531.           /* When we install the first one, set the VF_NORMAL_VALUE
  1532.              to be the current class, as this it is the most derived
  1533.              class.  Hopefully, this is not set to something else
  1534.              later.  (mrs) */
  1535.           vfields = b->vfields;
  1536.           while (vfields)
  1537.             {
  1538.               if (DECL_NAME (CLASSTYPE_VFIELD (t))
  1539.               == DECL_NAME (CLASSTYPE_VFIELD (basetype)))
  1540.             {
  1541.               VF_NORMAL_VALUE (vfields) = t;
  1542.               /* There should only be one of them!  And it should
  1543.                  always be found, if we get into here.  (mrs)  */
  1544.               break;
  1545.             }
  1546.               vfields = TREE_CHAIN (vfields);
  1547.             }
  1548.         }
  1549.         }
  1550.     }
  1551.     }
  1552.  
  1553.   /* Must come after offsets are fixed for all bases.  */
  1554.   for (i = 0; i < n_baseclasses; i++)
  1555.     {
  1556.       tree base_binfo = TREE_VEC_ELT (binfos, i);
  1557.       tree basetype = BINFO_TYPE (base_binfo);
  1558.  
  1559.       if (get_base_distance (basetype, t_binfo, 0, (tree*)0) == -2)
  1560.     {
  1561.       cp_warning ("direct base `%T' inaccessible in `%T' due to ambiguity",
  1562.               basetype, t);
  1563.       b->cant_synth_asn_ref = 1;
  1564.       b->cant_synth_copy_ctor = 1;
  1565.     }
  1566.     }
  1567.   {
  1568.     tree v = get_vbase_types (t_binfo);
  1569.  
  1570.     for (; v; v = TREE_CHAIN (v))
  1571.       {
  1572.     tree basetype = BINFO_TYPE (v);
  1573.     if (get_base_distance (basetype, t_binfo, 0, (tree*)0) == -2)
  1574.       {
  1575.         if (extra_warnings)
  1576.           cp_warning ("virtual base `%T' inaccessible in `%T' due to ambiguity",
  1577.               basetype, t);
  1578.         b->cant_synth_asn_ref = 1;
  1579.         b->cant_synth_copy_ctor = 1;
  1580.       }
  1581.       }
  1582.   }    
  1583.  
  1584.   {
  1585.     tree vfields;
  1586.     /* Find the base class with the largest number of virtual functions.  */
  1587.     for (vfields = b->vfields; vfields; vfields = TREE_CHAIN (vfields))
  1588.       {
  1589.     if (CLASSTYPE_VSIZE (VF_BASETYPE_VALUE (vfields)) > b->max_has_virtual)
  1590.       b->max_has_virtual = CLASSTYPE_VSIZE (VF_BASETYPE_VALUE (vfields));
  1591.     if (VF_DERIVED_VALUE (vfields)
  1592.         && CLASSTYPE_VSIZE (VF_DERIVED_VALUE (vfields)) > b->max_has_virtual)
  1593.       b->max_has_virtual = CLASSTYPE_VSIZE (VF_DERIVED_VALUE (vfields));
  1594.       }
  1595.   }
  1596.  
  1597.   if (b->vfield == 0)
  1598.     /* If all virtual functions come only from virtual baseclasses.  */
  1599.     return -1;
  1600.   return first_vfn_base_index;
  1601. }
  1602.  
  1603. static int
  1604. typecode_p (type, code)
  1605.      tree type;
  1606.      enum tree_code code;
  1607. {
  1608.   return (TREE_CODE (type) == code
  1609.       || (TREE_CODE (type) == REFERENCE_TYPE
  1610.           && TREE_CODE (TREE_TYPE (type)) == code));
  1611. }
  1612.  
  1613. /* Set memoizing fields and bits of T (and its variants) for later use.
  1614.    MAX_HAS_VIRTUAL is the largest size of any T's virtual function tables.  */
  1615. static void
  1616. finish_struct_bits (t, max_has_virtual)
  1617.      tree t;
  1618.      int max_has_virtual;
  1619. {
  1620.   int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
  1621.   tree method_vec = CLASSTYPE_METHOD_VEC (t);
  1622.  
  1623.   /* Fix up variants (if any).  */
  1624.   tree variants = TYPE_NEXT_VARIANT (t);
  1625.   while (variants)
  1626.     {
  1627.       /* These fields are in the _TYPE part of the node, not in
  1628.      the TYPE_LANG_SPECIFIC component, so they are not shared.  */
  1629.       TYPE_HAS_CONSTRUCTOR (variants) = TYPE_HAS_CONSTRUCTOR (t);
  1630.       TYPE_HAS_DESTRUCTOR (variants) = TYPE_HAS_DESTRUCTOR (t);
  1631.       TYPE_NEEDS_CONSTRUCTING (variants) = TYPE_NEEDS_CONSTRUCTING (t);
  1632.       TYPE_NEEDS_DESTRUCTOR (variants) = TYPE_NEEDS_DESTRUCTOR (t);
  1633.  
  1634.       TYPE_USES_COMPLEX_INHERITANCE (variants) = TYPE_USES_COMPLEX_INHERITANCE (t);
  1635.       TYPE_VIRTUAL_P (variants) = TYPE_VIRTUAL_P (t);
  1636.       TYPE_USES_VIRTUAL_BASECLASSES (variants) = TYPE_USES_VIRTUAL_BASECLASSES (t);
  1637.       /* Copy whatever these are holding today.  */
  1638.       TYPE_MIN_VALUE (variants) = TYPE_MIN_VALUE (t);
  1639.       TYPE_MAX_VALUE (variants) = TYPE_MAX_VALUE (t);
  1640.       variants = TYPE_NEXT_VARIANT (variants);
  1641.     }
  1642.  
  1643.   if (n_baseclasses && max_has_virtual)
  1644.     {
  1645.       /* Done by `finish_struct' for classes without baseclasses.  */
  1646.       int might_have_abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (t) != 0;
  1647.       tree binfos = TYPE_BINFO_BASETYPES (t);
  1648.       for (i = n_baseclasses-1; i >= 0; i--)
  1649.     {
  1650.       might_have_abstract_virtuals
  1651.         |= (CLASSTYPE_ABSTRACT_VIRTUALS (BINFO_TYPE (TREE_VEC_ELT (binfos, i))) != 0);
  1652.       if (might_have_abstract_virtuals)
  1653.         break;
  1654.     }
  1655.       if (might_have_abstract_virtuals)
  1656.     {
  1657.       /* We use error_mark_node from override_one_vtable to signal
  1658.          an artificial abstract. */
  1659.       if (CLASSTYPE_ABSTRACT_VIRTUALS (t) == error_mark_node)
  1660.         CLASSTYPE_ABSTRACT_VIRTUALS (t) = NULL_TREE;
  1661.       CLASSTYPE_ABSTRACT_VIRTUALS (t) = get_abstract_virtuals (t);
  1662.     }
  1663.     }
  1664.  
  1665.   if (n_baseclasses)
  1666.     {
  1667.       /* Notice whether this class has type conversion functions defined.  */
  1668.       tree binfo = TYPE_BINFO (t);
  1669.       tree binfos = BINFO_BASETYPES (binfo);
  1670.       tree basetype;
  1671.  
  1672.       for (i = n_baseclasses-1; i >= 0; i--)
  1673.     {
  1674.       basetype = BINFO_TYPE (TREE_VEC_ELT (binfos, i));
  1675.  
  1676.       if (TYPE_HAS_CONVERSION (basetype))
  1677.         {
  1678.           TYPE_HAS_CONVERSION (t) = 1;
  1679.           TYPE_HAS_INT_CONVERSION (t) |= TYPE_HAS_INT_CONVERSION (basetype);
  1680.           TYPE_HAS_REAL_CONVERSION (t) |= TYPE_HAS_REAL_CONVERSION (basetype);
  1681.         }
  1682.       if (CLASSTYPE_MAX_DEPTH (basetype) >= CLASSTYPE_MAX_DEPTH (t))
  1683.         CLASSTYPE_MAX_DEPTH (t) = CLASSTYPE_MAX_DEPTH (basetype) + 1;
  1684.     }
  1685.     }
  1686.  
  1687.   /* If this type has a copy constructor, force its mode to be BLKmode, and
  1688.      force its TREE_ADDRESSABLE bit to be nonzero.  This will cause it to
  1689.      be passed by invisible reference and prevent it from being returned in
  1690.      a register.  */
  1691.   if (! TYPE_HAS_TRIVIAL_INIT_REF (t))
  1692.     {
  1693.       tree variants;
  1694.       if (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL)
  1695.     DECL_MODE (TYPE_NAME (t)) = BLKmode;
  1696.       for (variants = t; variants; variants = TYPE_NEXT_VARIANT (variants))
  1697.     {
  1698.       TYPE_MODE (variants) = BLKmode;
  1699.       TREE_ADDRESSABLE (variants) = 1;
  1700.     }
  1701.     }
  1702. }
  1703.  
  1704. /* Add FN to the method_vec growing on the class_obstack.  Used by
  1705.    finish_struct_methods.  */
  1706. static void
  1707. grow_method (fn, method_vec_ptr)
  1708.      tree fn;
  1709.      tree *method_vec_ptr;
  1710. {
  1711.   tree method_vec = (tree)obstack_base (&class_obstack);
  1712.   tree *testp = &TREE_VEC_ELT (method_vec, 0);
  1713.   if (*testp == NULL_TREE)
  1714.     testp++;
  1715.   while (((HOST_WIDE_INT) testp
  1716.       < (HOST_WIDE_INT) obstack_next_free (&class_obstack))
  1717.      && DECL_NAME (*testp) != DECL_NAME (fn))
  1718.     testp++;
  1719.   if ((HOST_WIDE_INT) testp
  1720.       < (HOST_WIDE_INT) obstack_next_free (&class_obstack))
  1721.     {
  1722.       tree x, prev_x;
  1723.  
  1724.       for (x = *testp; x; x = DECL_CHAIN (x))
  1725.     {
  1726.       if (DECL_NAME (fn) == ansi_opname[(int) DELETE_EXPR]
  1727.           || DECL_NAME (fn) == ansi_opname[(int) VEC_DELETE_EXPR])
  1728.         {
  1729.           /* ANSI C++ June 5 1992 WP 12.5.5.1 */
  1730.           cp_error_at ("`%D' overloaded", fn);
  1731.           cp_error_at ("previous declaration as `%D' here", x);
  1732.         }
  1733.       if (DECL_ASSEMBLER_NAME (fn)==DECL_ASSEMBLER_NAME (x))
  1734.         {
  1735.           /* We complain about multiple destructors on sight,
  1736.          so we do not repeat the warning here.  Friend-friend
  1737.          ambiguities are warned about outside this loop.  */
  1738.           if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fn)))
  1739.         cp_error_at ("ambiguous method `%#D' in structure", fn);
  1740.           break;
  1741.         }
  1742.       prev_x = x;
  1743.     }
  1744.       if (x == 0)
  1745.     {
  1746.       if (*testp)
  1747.         DECL_CHAIN (prev_x) = fn;
  1748.       else
  1749.         *testp = fn;
  1750.     }
  1751.     }
  1752.   else
  1753.     {
  1754.       obstack_ptr_grow (&class_obstack, fn);
  1755.       *method_vec_ptr = (tree)obstack_base (&class_obstack);
  1756.     }
  1757. }
  1758.  
  1759. /* Warn about duplicate methods in fn_fields.  Also compact method
  1760.    lists so that lookup can be made faster.
  1761.  
  1762.    Algorithm: Outer loop builds lists by method name.  Inner loop
  1763.    checks for redundant method names within a list.
  1764.  
  1765.    Data Structure: List of method lists.  The outer list is a
  1766.    TREE_LIST, whose TREE_PURPOSE field is the field name and the
  1767.    TREE_VALUE is the DECL_CHAIN of the FUNCTION_DECLs.  TREE_CHAIN
  1768.    links the entire list of methods for TYPE_METHODS.  Friends are
  1769.    chained in the same way as member functions (? TREE_CHAIN or
  1770.    DECL_CHAIN), but they live in the TREE_TYPE field of the outer
  1771.    list.  That allows them to be quickly deleted, and requires no
  1772.    extra storage.
  1773.  
  1774.    If there are any constructors/destructors, they are moved to the
  1775.    front of the list.  This makes pushclass more efficient.
  1776.  
  1777.    We also link each field which has shares a name with its baseclass
  1778.    to the head of the list of fields for that base class.  This allows
  1779.    us to reduce search time in places like `build_method_call' to
  1780.    consider only reasonably likely functions.  */
  1781.  
  1782. static tree
  1783. finish_struct_methods (t, fn_fields, nonprivate_method)
  1784.      tree t;
  1785.      tree fn_fields;
  1786.      int nonprivate_method;
  1787. {
  1788.   tree method_vec;
  1789.   tree save_fn_fields = tree_cons (NULL_TREE, NULL_TREE, fn_fields);
  1790.   tree lastp;
  1791.   tree name = constructor_name (t);
  1792.   int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
  1793.  
  1794.   /* Now prepare to gather fn_fields into vector.  */
  1795.   struct obstack *ambient_obstack = current_obstack;
  1796.   current_obstack = &class_obstack;
  1797.   method_vec = make_node (TREE_VEC);
  1798.   /* Room has been saved for constructors and destructors.  */
  1799.   current_obstack = ambient_obstack;
  1800.   /* Now make this a live vector.  */
  1801.   obstack_free (&class_obstack, method_vec);
  1802.   obstack_blank (&class_obstack, sizeof (struct tree_vec));
  1803.  
  1804.   /* First fill in entry 0 with the constructors, and the next few with
  1805.      type conversion operators (if any).  */
  1806.  
  1807.   for (lastp = save_fn_fields; fn_fields; fn_fields = TREE_CHAIN (lastp))
  1808.     {
  1809.       tree fn_name = DECL_NAME (fn_fields);
  1810.       if (fn_name == NULL_TREE)
  1811.     fn_name = name;
  1812.  
  1813.       /* Clear out this flag.
  1814.  
  1815.      @@ Doug may figure out how to break
  1816.      @@ this with nested classes and friends.  */
  1817.       DECL_IN_AGGR_P (fn_fields) = 0;
  1818.  
  1819.       /* Note here that a copy ctor is private, so we don't dare generate
  1820.       a default copy constructor for a class that has a member
  1821.       of this type without making sure they have access to it.  */
  1822.       if (fn_name == name)
  1823.      {
  1824.        tree parmtypes = FUNCTION_ARG_CHAIN (fn_fields);
  1825.        tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node;
  1826.       
  1827.        if (TREE_CODE (parmtype) == REFERENCE_TYPE
  1828.            && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == t)
  1829.          {
  1830.            if (TREE_CHAIN (parmtypes) == NULL_TREE
  1831.            || TREE_CHAIN (parmtypes) == void_list_node
  1832.            || TREE_PURPOSE (TREE_CHAIN (parmtypes)))
  1833.          {
  1834.            if (TREE_PROTECTED (fn_fields))
  1835.              TYPE_HAS_NONPUBLIC_CTOR (t) = 1;
  1836.            else if (TREE_PRIVATE (fn_fields))
  1837.              TYPE_HAS_NONPUBLIC_CTOR (t) = 2;
  1838.          }
  1839.          }
  1840.       /* Constructors are handled easily in search routines.  */
  1841.       DECL_CHAIN (fn_fields) = TREE_VEC_ELT (method_vec, 0);
  1842.       TREE_VEC_ELT (method_vec, 0) = fn_fields;
  1843.      }
  1844.       else if (IDENTIFIER_TYPENAME_P (fn_name))
  1845.     {
  1846.       tree return_type = TREE_TYPE (TREE_TYPE (fn_fields));
  1847.  
  1848.       if (typecode_p (return_type, INTEGER_TYPE)
  1849.           || typecode_p (return_type, BOOLEAN_TYPE)
  1850.           || typecode_p (return_type, ENUMERAL_TYPE))
  1851.         TYPE_HAS_INT_CONVERSION (t) = 1;
  1852.       else if (typecode_p (return_type, REAL_TYPE))
  1853.         TYPE_HAS_REAL_CONVERSION (t) = 1;
  1854.  
  1855.       grow_method (fn_fields, &method_vec);
  1856.     }
  1857.       else
  1858.     {
  1859.       lastp = fn_fields;
  1860.       continue;
  1861.     }
  1862.  
  1863.       TREE_CHAIN (lastp) = TREE_CHAIN (fn_fields);
  1864.       TREE_CHAIN (fn_fields) = NULL_TREE;
  1865.     }
  1866.  
  1867.   fn_fields = TREE_CHAIN (save_fn_fields);
  1868.   while (fn_fields)
  1869.     {
  1870.       tree nextp;
  1871.       tree fn_name = DECL_NAME (fn_fields);
  1872.       if (fn_name == NULL_TREE)
  1873.     fn_name = name;
  1874.  
  1875.       nextp = TREE_CHAIN (fn_fields);
  1876.       TREE_CHAIN (fn_fields) = NULL_TREE;
  1877.  
  1878.       if (fn_name == ansi_opname[(int) MODIFY_EXPR])
  1879.     {
  1880.       tree parmtype = TREE_VALUE (FUNCTION_ARG_CHAIN (fn_fields));
  1881.  
  1882.       if (copy_assignment_arg_p (parmtype, DECL_VIRTUAL_P (fn_fields)))
  1883.         {
  1884.           if (TREE_PROTECTED (fn_fields))
  1885.         TYPE_HAS_NONPUBLIC_ASSIGN_REF (t) = 1;
  1886.           else if (TREE_PRIVATE (fn_fields))
  1887.         TYPE_HAS_NONPUBLIC_ASSIGN_REF (t) = 2;
  1888.         }
  1889.     }
  1890.  
  1891.       grow_method (fn_fields, &method_vec);
  1892.       fn_fields = nextp;
  1893.     }
  1894.  
  1895.   TREE_VEC_LENGTH (method_vec) = (tree *)obstack_next_free (&class_obstack)
  1896.     - (&TREE_VEC_ELT (method_vec, 0));
  1897.   obstack_finish (&class_obstack);
  1898.   CLASSTYPE_METHOD_VEC (t) = method_vec;
  1899.  
  1900.   if (nonprivate_method == 0
  1901.       && CLASSTYPE_FRIEND_CLASSES (t) == NULL_TREE
  1902.       && DECL_FRIENDLIST (TYPE_NAME (t)) == NULL_TREE)
  1903.     {
  1904.       tree binfos = BINFO_BASETYPES (TYPE_BINFO (t));
  1905.       for (i = 0; i < n_baseclasses; i++)
  1906.     if (TREE_VIA_PUBLIC (TREE_VEC_ELT (binfos, i))
  1907.         || TREE_VIA_PROTECTED (TREE_VEC_ELT (binfos, i)))
  1908.       {
  1909.         nonprivate_method = 1;
  1910.         break;
  1911.       }
  1912.       if (nonprivate_method == 0)
  1913.     cp_warning ("all member functions in class `%T' are private", t);
  1914.     }
  1915.  
  1916.   /* If there are constructors (and destructors), they are at the
  1917.      front.  Place destructors at very front.  Also warn if all
  1918.      constructors and/or destructors are private (in which case this
  1919.      class is effectively unusable.  */
  1920.   if (TYPE_HAS_DESTRUCTOR (t))
  1921.     {
  1922.       tree dtor, prev;
  1923.  
  1924.       for (dtor = TREE_VEC_ELT (method_vec, 0);
  1925.        dtor;
  1926.        prev = dtor, dtor = DECL_CHAIN (dtor))
  1927.     {
  1928.       if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (dtor)))
  1929.         {
  1930.           if (TREE_PRIVATE (dtor)
  1931.           && CLASSTYPE_FRIEND_CLASSES (t) == NULL_TREE
  1932.           && DECL_FRIENDLIST (TYPE_NAME (t)) == NULL_TREE
  1933.           && warn_ctor_dtor_privacy)
  1934.         cp_warning ("`%#T' only defines a private destructor and has no friends",
  1935.                 t);
  1936.           break;
  1937.         }
  1938.     }
  1939.  
  1940.       /* Wild parse errors can cause this to happen.  */
  1941.       if (dtor == NULL_TREE)
  1942.     TYPE_HAS_DESTRUCTOR (t) = 0;
  1943.       else if (dtor != TREE_VEC_ELT (method_vec, 0))
  1944.     {
  1945.       DECL_CHAIN (prev) = DECL_CHAIN (dtor);
  1946.       DECL_CHAIN (dtor) = TREE_VEC_ELT (method_vec, 0);
  1947.       TREE_VEC_ELT (method_vec, 0) = dtor;
  1948.     }
  1949.     }
  1950.  
  1951.   /* Now for each member function (except for constructors and
  1952.      destructors), compute where member functions of the same
  1953.      name reside in base classes.  */
  1954.   if (n_baseclasses != 0
  1955.       && TREE_VEC_LENGTH (method_vec) > 1)
  1956.     {
  1957.       int len = TREE_VEC_LENGTH (method_vec);
  1958.       tree baselink_vec = make_tree_vec (len);
  1959.       int any_links = 0;
  1960.       tree baselink_binfo = build_tree_list (NULL_TREE, TYPE_BINFO (t));
  1961.  
  1962.       for (i = 1; i < len; i++)
  1963.     {
  1964.       TREE_VEC_ELT (baselink_vec, i)
  1965.         = get_baselinks (baselink_binfo, t, DECL_NAME (TREE_VEC_ELT (method_vec, i)));
  1966.       if (TREE_VEC_ELT (baselink_vec, i) != 0)
  1967.         any_links = 1;
  1968.     }
  1969.       if (any_links != 0)
  1970.     CLASSTYPE_BASELINK_VEC (t) = baselink_vec;
  1971.       else
  1972.     obstack_free (current_obstack, baselink_vec);
  1973.     }
  1974.  
  1975.   /* Now add the methods to the TYPE_METHODS of T, arranged in a chain.  */
  1976.   {
  1977.     tree x, last_x = NULL_TREE;
  1978.     int limit = TREE_VEC_LENGTH (method_vec);
  1979.  
  1980.     for (i = 1; i < limit; i++)
  1981.       {
  1982.     for (x = TREE_VEC_ELT (method_vec, i); x; x = DECL_CHAIN (x))
  1983.       {
  1984.         if (last_x != NULL_TREE)
  1985.           TREE_CHAIN (last_x) = x;
  1986.         last_x = x;
  1987.       }
  1988.       }
  1989.  
  1990.     /* Put ctors and dtors at the front of the list.  */
  1991.     x = TREE_VEC_ELT (method_vec, 0);
  1992.     if (x)
  1993.       {
  1994.     while (DECL_CHAIN (x))
  1995.       {
  1996.         /* Let's avoid being circular about this.  */
  1997.         if (x == DECL_CHAIN (x))
  1998.           break;
  1999.         TREE_CHAIN (x) = DECL_CHAIN (x);
  2000.         x = DECL_CHAIN (x);
  2001.       }
  2002.     if (TREE_VEC_LENGTH (method_vec) > 1)
  2003.       TREE_CHAIN (x) = TREE_VEC_ELT (method_vec, 1);
  2004.     else
  2005.       TREE_CHAIN (x) = NULL_TREE;
  2006.       }
  2007.   }
  2008.  
  2009.   TYPE_METHODS (t) = method_vec;
  2010.  
  2011.   return method_vec;
  2012. }
  2013.  
  2014. /* Emit error when a duplicate definition of a type is seen.  Patch up. */
  2015.  
  2016. void
  2017. duplicate_tag_error (t)
  2018.      tree t;
  2019. {
  2020.   cp_error ("redefinition of `%#T'", t);
  2021.   cp_error_at ("previous definition here", t);
  2022.  
  2023.   /* Pretend we haven't defined this type.  */
  2024.  
  2025.   /* All of the component_decl's were TREE_CHAINed together in the parser.
  2026.      finish_struct_methods walks these chains and assembles all methods with
  2027.      the same base name into DECL_CHAINs. Now we don't need the parser chains
  2028.      anymore, so we unravel them.
  2029.    */
  2030.   /*
  2031.    * This used to be in finish_struct, but it turns out that the
  2032.    * TREE_CHAIN is used by dbxout_type_methods and perhaps some other things...
  2033.    */
  2034.   if (CLASSTYPE_METHOD_VEC(t)) 
  2035.     {
  2036.       tree tv = CLASSTYPE_METHOD_VEC(t);
  2037.       int i, len  = TREE_VEC_LENGTH (tv);
  2038.       for (i = 0; i < len; i++)
  2039.     {
  2040.       tree unchain = TREE_VEC_ELT (tv, i);
  2041.       while (unchain != NULL_TREE) 
  2042.         {
  2043.           TREE_CHAIN (unchain) = NULL_TREE;
  2044.           unchain = DECL_CHAIN(unchain);
  2045.         }
  2046.     }
  2047.     }
  2048.  
  2049.   if (TYPE_LANG_SPECIFIC (t))
  2050.     {
  2051.       tree as_list = CLASSTYPE_AS_LIST (t);
  2052.       tree binfo = TYPE_BINFO (t);
  2053.       tree binfo_as_list = CLASSTYPE_BINFO_AS_LIST (t);
  2054.       int interface_only = CLASSTYPE_INTERFACE_ONLY (t);
  2055.       int interface_unknown = CLASSTYPE_INTERFACE_UNKNOWN (t);
  2056.  
  2057.       bzero ((char *) TYPE_LANG_SPECIFIC (t), sizeof (struct lang_type));
  2058.       BINFO_BASETYPES(binfo) = NULL_TREE;
  2059.  
  2060.       CLASSTYPE_AS_LIST (t) = as_list;
  2061.       TYPE_BINFO (t) = binfo;
  2062.       CLASSTYPE_BINFO_AS_LIST (t) = binfo_as_list;
  2063.       CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
  2064.       SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, interface_unknown);
  2065.       CLASSTYPE_VBASE_SIZE (t) = integer_zero_node;
  2066.       TYPE_REDEFINED (t) = 1;
  2067.     }
  2068.   TYPE_SIZE (t) = NULL_TREE;
  2069.   TYPE_MODE (t) = VOIDmode;
  2070.   TYPE_FIELDS (t) = NULL_TREE;
  2071.   TYPE_METHODS (t) = NULL_TREE;
  2072.   TYPE_VFIELD (t) = NULL_TREE;
  2073.   TYPE_CONTEXT (t) = NULL_TREE;
  2074. }
  2075.  
  2076. /* finish up all new vtables. */
  2077. static void
  2078. finish_vtbls (binfo, do_self, t)
  2079.      tree binfo, t;
  2080.      int do_self;
  2081. {
  2082.   tree binfos = BINFO_BASETYPES (binfo);
  2083.   int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
  2084.  
  2085.   /* Should we use something besides CLASSTYPE_VFIELDS? */
  2086.   if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
  2087.     {
  2088.       if (BINFO_NEW_VTABLE_MARKED (binfo))
  2089.     {
  2090.       tree decl, context;
  2091.  
  2092.       decl = BINFO_VTABLE (binfo);
  2093.       context = DECL_CONTEXT (decl);
  2094.       DECL_CONTEXT (decl) = 0;
  2095.       if (write_virtuals >= 0
  2096.           && DECL_INITIAL (decl) != BINFO_VIRTUALS (binfo))
  2097.         DECL_INITIAL (decl) = build_nt (CONSTRUCTOR, NULL_TREE,
  2098.                         BINFO_VIRTUALS (binfo));
  2099.       cp_finish_decl (decl, DECL_INITIAL (decl), NULL_TREE, 0, 0);
  2100.       DECL_CONTEXT (decl) = context;
  2101.     }
  2102.       CLEAR_BINFO_NEW_VTABLE_MARKED (binfo);
  2103.     }
  2104.  
  2105.   for (i = 0; i < n_baselinks; i++)
  2106.     {
  2107.       tree base_binfo = TREE_VEC_ELT (binfos, i);
  2108.       int is_not_base_vtable =
  2109.     i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
  2110.       if (TREE_VIA_VIRTUAL (base_binfo))
  2111.     {
  2112.       base_binfo = binfo_member (BINFO_TYPE (base_binfo), CLASSTYPE_VBASECLASSES (t));
  2113.     }
  2114.       finish_vtbls (base_binfo, is_not_base_vtable, t);
  2115.     }
  2116. }
  2117.  
  2118. /* True if we should override the given BASE_FNDECL with the given
  2119.    FNDECL.  */
  2120. static int
  2121. overrides (fndecl, base_fndecl)
  2122.      tree fndecl, base_fndecl;
  2123. {
  2124.   /* Destructors have special names. */
  2125.   if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (base_fndecl)) &&
  2126.       DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
  2127.     return 1;
  2128.   if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (base_fndecl)) ||
  2129.       DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
  2130.     return 0;
  2131.   if (DECL_NAME (fndecl) == DECL_NAME (base_fndecl))
  2132.     {
  2133.       tree rettype, base_rettype, types, base_types;
  2134. #if 0
  2135.       retypes = TREE_TYPE (TREE_TYPE (fndecl));
  2136.       base_retypes = TREE_TYPE (TREE_TYPE (base_fndecl));
  2137. #endif
  2138.       types = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
  2139.       base_types = TYPE_ARG_TYPES (TREE_TYPE (base_fndecl));
  2140.       if ((TYPE_READONLY (TREE_TYPE (TREE_VALUE (base_types)))
  2141.        == TYPE_READONLY (TREE_TYPE (TREE_VALUE (types))))
  2142.       && compparms (TREE_CHAIN (base_types), TREE_CHAIN (types), 3))
  2143.     return 1;
  2144.     }
  2145.   return 0;
  2146. }
  2147.  
  2148. static tree
  2149. get_class_offset_1 (parent, binfo, context, t, fndecl)
  2150.      tree parent, binfo, context, t, fndecl;
  2151. {
  2152.   tree binfos = BINFO_BASETYPES (binfo);
  2153.   int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
  2154.   tree rval = NULL_TREE;
  2155.  
  2156.   if (binfo == parent)
  2157.     return error_mark_node;
  2158.  
  2159.   for (i = 0; i < n_baselinks; i++)
  2160.     {
  2161.       tree base_binfo = TREE_VEC_ELT (binfos, i);
  2162.       tree nrval;
  2163.  
  2164.       if (TREE_VIA_VIRTUAL (base_binfo))
  2165.     base_binfo = binfo_member (BINFO_TYPE (base_binfo),
  2166.                    CLASSTYPE_VBASECLASSES (t));
  2167.       nrval = get_class_offset_1 (parent, base_binfo, context, t, fndecl);
  2168.       /* See if we have a new value */
  2169.       if (nrval && (nrval != error_mark_node || rval==0))
  2170.     {
  2171.       /* Only compare if we have two offsets */
  2172.       if (rval && rval != error_mark_node
  2173.           && ! tree_int_cst_equal (nrval, rval))
  2174.         {
  2175.           /* Only give error if the two offsets are different */
  2176.           error ("every virtual function must have a unique final overrider");
  2177.           cp_error ("  found two (or more) `%T' class subobjects in `%T'", context, t);
  2178.           cp_error ("  with virtual `%D' from virtual base class", fndecl);
  2179.           return rval;
  2180.         }
  2181.       rval = nrval;
  2182.     }
  2183.     
  2184.       if (rval && BINFO_TYPE (binfo) == context)
  2185.     {
  2186.       my_friendly_assert (rval == error_mark_node
  2187.                   || tree_int_cst_equal (rval, BINFO_OFFSET (binfo)), 999);
  2188.       rval = BINFO_OFFSET (binfo);
  2189.     }
  2190.     }
  2191.   return rval;
  2192. }
  2193.  
  2194. /* Get the offset to the CONTEXT subobject that is related to the
  2195.    given BINFO.  */
  2196. static tree
  2197. get_class_offset (context, t, binfo, fndecl)
  2198.      tree context, t, binfo, fndecl;
  2199. {
  2200.   tree first_binfo = binfo;
  2201.   tree offset;
  2202.   int i;
  2203.  
  2204.   if (context == t)
  2205.     return integer_zero_node;
  2206.  
  2207.   if (BINFO_TYPE (binfo) == context)
  2208.     return BINFO_OFFSET (binfo);
  2209.  
  2210.   /* Check less derived binfos first.  */
  2211.   while (BINFO_BASETYPES (binfo)
  2212.      && (i=CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo))) != -1)
  2213.     {
  2214.       tree binfos = BINFO_BASETYPES (binfo);
  2215.       binfo = TREE_VEC_ELT (binfos, i);
  2216.       if (BINFO_TYPE (binfo) == context)
  2217.     return BINFO_OFFSET (binfo);
  2218.     }
  2219.  
  2220.   /* Ok, not found in the less derived binfos, now check the more
  2221.      derived binfos. */
  2222.   offset = get_class_offset_1 (first_binfo, TYPE_BINFO (t), context, t, fndecl);
  2223.   if (offset==0 || TREE_CODE (offset) != INTEGER_CST)
  2224.     my_friendly_abort (999);    /* we have to find it.  */
  2225.   return offset;
  2226. }
  2227.  
  2228. static void
  2229. modify_one_vtable (binfo, t, fndecl, pfn)
  2230.      tree binfo, t, fndecl, pfn;
  2231. {
  2232.   tree virtuals = BINFO_VIRTUALS (binfo);
  2233.   tree old_rtti;
  2234.   unsigned HOST_WIDE_INT n;
  2235.   
  2236.   /* update rtti entry */
  2237.   if (flag_rtti)
  2238.     {
  2239.       if (binfo == TYPE_BINFO (t))
  2240.     {
  2241.       if (! BINFO_NEW_VTABLE_MARKED (binfo))
  2242.         build_vtable (TYPE_BINFO (DECL_CONTEXT (CLASSTYPE_VFIELD (t))), t);
  2243.     }
  2244.       else
  2245.     {
  2246.       if (! BINFO_NEW_VTABLE_MARKED (binfo))
  2247.         prepare_fresh_vtable (binfo, t);
  2248.     }
  2249.     }
  2250.   if (fndecl == NULL_TREE) return;
  2251.  
  2252.   /* Skip RTTI fake object. */
  2253.   n = 1;
  2254.   if (virtuals)
  2255.     virtuals = TREE_CHAIN (virtuals);
  2256.   while (virtuals)
  2257.     {
  2258.       tree current_fndecl = TREE_VALUE (virtuals);
  2259.       current_fndecl = FNADDR_FROM_VTABLE_ENTRY (current_fndecl);
  2260.       current_fndecl = TREE_OPERAND (current_fndecl, 0);
  2261.       if (current_fndecl && overrides (fndecl, current_fndecl))
  2262.     {
  2263.       tree base_offset, offset;
  2264.       tree context = DECL_CLASS_CONTEXT (fndecl);
  2265.       tree vfield = CLASSTYPE_VFIELD (t);
  2266.       tree this_offset;
  2267.  
  2268.       offset = get_class_offset (context, t, binfo, fndecl);
  2269.  
  2270.       /* Find the right offset for the this pointer based on the
  2271.          base class we just found.  We have to take into
  2272.          consideration the virtual base class pointers that we
  2273.          stick in before the virtual function table pointer.
  2274.  
  2275.          Also, we want just the delta between the most base class
  2276.          that we derived this vfield from and us.  */
  2277.       base_offset = size_binop (PLUS_EXPR,
  2278.                     get_derived_offset (binfo, DECL_CONTEXT (current_fndecl)),
  2279.                     BINFO_OFFSET (binfo));
  2280.       this_offset = size_binop (MINUS_EXPR, offset, base_offset);
  2281.  
  2282.       /* Make sure we can modify the derived association with immunity.  */
  2283.       if (TREE_USED (binfo))
  2284.         my_friendly_assert (0, 999);
  2285.  
  2286.       if (binfo == TYPE_BINFO (t))
  2287.         {
  2288.           /* In this case, it is *type*'s vtable we are modifying.
  2289.          We start with the approximation that it's vtable is that
  2290.          of the immediate base class.  */
  2291.           if (! BINFO_NEW_VTABLE_MARKED (binfo))
  2292.         build_vtable (TYPE_BINFO (DECL_CONTEXT (vfield)), t);
  2293.         }
  2294.       else
  2295.         {
  2296.           /* This is our very own copy of `basetype' to play with.
  2297.          Later, we will fill in all the virtual functions
  2298.          that override the virtual functions in these base classes
  2299.          which are not defined by the current type.  */
  2300.           if (! BINFO_NEW_VTABLE_MARKED (binfo))
  2301.         prepare_fresh_vtable (binfo, t);
  2302.         }
  2303.  
  2304. #ifdef NOTQUITE
  2305.       cp_warning ("in %D", DECL_NAME (BINFO_VTABLE (binfo)));
  2306. #endif
  2307.       modify_vtable_entry (get_vtable_entry_n (BINFO_VIRTUALS (binfo), n),
  2308.                    build_vtable_entry (this_offset, pfn),
  2309.                    fndecl);
  2310.     }
  2311.       ++n;
  2312.       virtuals = TREE_CHAIN (virtuals);
  2313.     }
  2314. }
  2315.  
  2316. /* These are the ones that are not through virtual base classes. */
  2317. static void
  2318. modify_all_direct_vtables (binfo, do_self, t, fndecl, pfn)
  2319.      tree binfo, t, fndecl, pfn;
  2320.      int do_self;
  2321. {
  2322.   tree binfos = BINFO_BASETYPES (binfo);
  2323.   int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
  2324.  
  2325.   /* Should we use something besides CLASSTYPE_VFIELDS? */
  2326.   if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
  2327.     {
  2328.       modify_one_vtable (binfo, t, fndecl, pfn);
  2329.     }
  2330.  
  2331.   for (i = 0; i < n_baselinks; i++)
  2332.     {
  2333.       tree base_binfo = TREE_VEC_ELT (binfos, i);
  2334.       int is_not_base_vtable =
  2335.     i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
  2336.       if (! TREE_VIA_VIRTUAL (base_binfo))
  2337.     modify_all_direct_vtables (base_binfo, is_not_base_vtable, t, fndecl, pfn);
  2338.     }
  2339. }
  2340.  
  2341. /* Fixup all the delta entries in this one vtable that need updating.  */
  2342. static void
  2343. fixup_vtable_deltas1 (binfo, t)
  2344.      tree binfo, t;
  2345. {
  2346.   tree virtuals = BINFO_VIRTUALS (binfo);
  2347.   unsigned HOST_WIDE_INT n;
  2348.   
  2349.   /* Skip RTTI fake object. */
  2350.   n = 1;
  2351.   if (virtuals)
  2352.     virtuals = TREE_CHAIN (virtuals);
  2353.   while (virtuals)
  2354.     {
  2355.       tree fndecl = TREE_VALUE (virtuals);
  2356.       tree pfn = FNADDR_FROM_VTABLE_ENTRY (fndecl);
  2357.       tree delta = DELTA_FROM_VTABLE_ENTRY (fndecl);
  2358.       fndecl = TREE_OPERAND (pfn, 0);
  2359.       if (fndecl)
  2360.     {
  2361.       tree base_offset, offset;
  2362.       tree context = DECL_CLASS_CONTEXT (fndecl);
  2363.       tree vfield = CLASSTYPE_VFIELD (t);
  2364.       tree this_offset;
  2365.  
  2366.       offset = get_class_offset (context, t, binfo, fndecl);
  2367.  
  2368.       /* Find the right offset for the this pointer based on the
  2369.          base class we just found.  We have to take into
  2370.          consideration the virtual base class pointers that we
  2371.          stick in before the virtual function table pointer.
  2372.  
  2373.          Also, we want just the delta between the most base class
  2374.          that we derived this vfield from and us.  */
  2375.       base_offset = size_binop (PLUS_EXPR,
  2376.                     get_derived_offset (binfo, DECL_CONTEXT (fndecl)),
  2377.                     BINFO_OFFSET (binfo));
  2378.       this_offset = size_binop (MINUS_EXPR, offset, base_offset);
  2379.  
  2380.       if (! tree_int_cst_equal (this_offset, delta))
  2381.         {
  2382.           /* Make sure we can modify the derived association with immunity.  */
  2383.           if (TREE_USED (binfo))
  2384.         my_friendly_assert (0, 999);
  2385.  
  2386.           if (binfo == TYPE_BINFO (t))
  2387.         {
  2388.           /* In this case, it is *type*'s vtable we are modifying.
  2389.              We start with the approximation that it's vtable is that
  2390.              of the immediate base class.  */
  2391.           if (! BINFO_NEW_VTABLE_MARKED (binfo))
  2392.             build_vtable (TYPE_BINFO (DECL_CONTEXT (vfield)), t);
  2393.         }
  2394.           else
  2395.         {
  2396.           /* This is our very own copy of `basetype' to play with.
  2397.              Later, we will fill in all the virtual functions
  2398.              that override the virtual functions in these base classes
  2399.              which are not defined by the current type.  */
  2400.           if (! BINFO_NEW_VTABLE_MARKED (binfo))
  2401.             prepare_fresh_vtable (binfo, t);
  2402.         }
  2403.  
  2404.           modify_vtable_entry (get_vtable_entry_n (BINFO_VIRTUALS (binfo), n),
  2405.                    build_vtable_entry (this_offset, pfn),
  2406.                    fndecl);
  2407.         }
  2408.     }
  2409.       ++n;
  2410.       virtuals = TREE_CHAIN (virtuals);
  2411.     }
  2412. }
  2413.  
  2414. /* Fixup all the delta entries in all the direct vtables that need updating.
  2415.    This happens when we have non-overridden virtual functions from a
  2416.    virtual base class, that are at a different offset, in the new
  2417.    hierarchy, because the layout of the virtual bases has changed.  */
  2418. static void
  2419. fixup_vtable_deltas (binfo, init_self, t)
  2420.      tree binfo, t;
  2421.      int init_self;
  2422. {
  2423.   tree binfos = BINFO_BASETYPES (binfo);
  2424.   int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
  2425.  
  2426.   for (i = 0; i < n_baselinks; i++)
  2427.     {
  2428.       tree base_binfo = TREE_VEC_ELT (binfos, i);
  2429.       int is_not_base_vtable =
  2430.     i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
  2431.       if (! TREE_VIA_VIRTUAL (base_binfo))
  2432.     fixup_vtable_deltas (base_binfo, is_not_base_vtable, t);
  2433.     }
  2434.   /* Should we use something besides CLASSTYPE_VFIELDS? */
  2435.   if (init_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
  2436.     {
  2437.       fixup_vtable_deltas1 (binfo, t);
  2438.     }
  2439. }
  2440.  
  2441. /* These are the ones that are through virtual base classes. */
  2442. static void
  2443. modify_all_indirect_vtables (binfo, do_self, via_virtual, t, fndecl, pfn)
  2444.      tree binfo, t, fndecl, pfn;
  2445.      int do_self, via_virtual;
  2446. {
  2447.   tree binfos = BINFO_BASETYPES (binfo);
  2448.   int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
  2449.  
  2450.   /* Should we use something besides CLASSTYPE_VFIELDS? */
  2451.   if (do_self && via_virtual && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
  2452.     {
  2453.       modify_one_vtable (binfo, t, fndecl, pfn);
  2454.     }
  2455.  
  2456.   for (i = 0; i < n_baselinks; i++)
  2457.     {
  2458.       tree base_binfo = TREE_VEC_ELT (binfos, i);
  2459.       int is_not_base_vtable =
  2460.     i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
  2461.       if (TREE_VIA_VIRTUAL (base_binfo))
  2462.     {
  2463.       via_virtual = 1;
  2464.       base_binfo = binfo_member (BINFO_TYPE (base_binfo), CLASSTYPE_VBASECLASSES (t));
  2465.     }
  2466.       modify_all_indirect_vtables (base_binfo, is_not_base_vtable, via_virtual, t, fndecl, pfn);
  2467.     }
  2468. }
  2469.  
  2470. static void
  2471. modify_all_vtables (t, fndecl, vfn)
  2472.      tree t, fndecl, vfn;
  2473. {
  2474.   /* Do these first, so that we will make use of any non-virtual class's
  2475.      vtable, over a virtual classes vtable. */
  2476.   modify_all_direct_vtables (TYPE_BINFO (t), 1, t, fndecl, vfn);
  2477.   if (TYPE_USES_VIRTUAL_BASECLASSES (t))
  2478.     modify_all_indirect_vtables (TYPE_BINFO (t), 1, 0, t, fndecl, vfn);
  2479. }
  2480.  
  2481. /* Here, we already know that they match in every respect.
  2482.    All we have to check is where they had their declarations.  */
  2483. static int 
  2484. strictly_overrides (fndecl1, fndecl2)
  2485.      tree fndecl1, fndecl2;
  2486. {
  2487.   int distance = get_base_distance (DECL_CLASS_CONTEXT (fndecl2),
  2488.                     DECL_CLASS_CONTEXT (fndecl1),
  2489.                     0, (tree *)0);
  2490.   if (distance == -2 || distance > 0)
  2491.     return 1;
  2492.   return 0;
  2493. }
  2494.  
  2495. /* Merge overrides for one vtable.
  2496.    If we want to merge in same function, we are fine.
  2497.    else
  2498.      if one has a DECL_CLASS_CONTEXT that is a parent of the
  2499.        other, than choose the more derived one
  2500.      else
  2501.        potentially ill-formed (see 10.3 [class.virtual])
  2502.        we have to check later to see if there was an
  2503.        override in this class.  If there was ok, if not
  2504.        then it is ill-formed.  (mrs)
  2505.  
  2506.    We take special care to reuse a vtable, if we can.  */
  2507. static void
  2508. override_one_vtable (binfo, old, t)
  2509.      tree binfo, old, t;
  2510. {
  2511.   tree virtuals = BINFO_VIRTUALS (binfo);
  2512.   tree old_virtuals = BINFO_VIRTUALS (old);
  2513.   enum { REUSE_NEW, REUSE_OLD, UNDECIDED, NEITHER } choose = UNDECIDED;
  2514.  
  2515.   /* If we have already committed to modifying it, then don't try and
  2516.      reuse another vtable. */
  2517.   if (BINFO_NEW_VTABLE_MARKED (binfo))
  2518.     choose = NEITHER;
  2519.  
  2520.   /* Skip RTTI fake object. */
  2521.   virtuals = TREE_CHAIN (virtuals);
  2522.   old_virtuals = TREE_CHAIN (old_virtuals);
  2523.  
  2524.   while (virtuals)
  2525.     {
  2526.       tree fndecl = TREE_VALUE (virtuals);
  2527.       tree old_fndecl = TREE_VALUE (old_virtuals);
  2528.       fndecl = FNADDR_FROM_VTABLE_ENTRY (fndecl);
  2529.       old_fndecl = FNADDR_FROM_VTABLE_ENTRY (old_fndecl);
  2530.       fndecl = TREE_OPERAND (fndecl, 0);
  2531.       old_fndecl = TREE_OPERAND (old_fndecl, 0);
  2532.       /* First check to see if they are the same. */
  2533.       if (DECL_ASSEMBLER_NAME (fndecl) == DECL_ASSEMBLER_NAME (old_fndecl))
  2534.     {
  2535.       /* No need to do anything. */
  2536.     }
  2537.       else if (strictly_overrides (fndecl, old_fndecl))
  2538.     {
  2539.       if (choose == UNDECIDED)
  2540.         choose = REUSE_NEW;
  2541.       else if (choose == REUSE_OLD)
  2542.         {
  2543.           choose = NEITHER;
  2544.           if (! BINFO_NEW_VTABLE_MARKED (binfo))
  2545.         {
  2546.           prepare_fresh_vtable (binfo, t);
  2547.           override_one_vtable (binfo, old, t);
  2548.           return;
  2549.         }
  2550.         }
  2551.     }
  2552.       else if (strictly_overrides (old_fndecl, fndecl))
  2553.     {
  2554.       if (choose == UNDECIDED)
  2555.         choose = REUSE_OLD;
  2556.       else if (choose == REUSE_NEW)
  2557.         {
  2558.           choose = NEITHER;
  2559.           if (! BINFO_NEW_VTABLE_MARKED (binfo))
  2560.         {
  2561.           prepare_fresh_vtable (binfo, t);
  2562.           override_one_vtable (binfo, old, t);
  2563.           return;
  2564.         }
  2565.           TREE_VALUE (virtuals) = TREE_VALUE (old_virtuals);
  2566.         }
  2567.       else if (choose == NEITHER)
  2568.         {
  2569.           TREE_VALUE (virtuals) = TREE_VALUE (old_virtuals);
  2570.         }  
  2571.     }
  2572.       else
  2573.     {
  2574.       choose = NEITHER;
  2575.       if (! BINFO_NEW_VTABLE_MARKED (binfo))
  2576.         {
  2577.           prepare_fresh_vtable (binfo, t);
  2578.           override_one_vtable (binfo, old, t);
  2579.           return;
  2580.         }
  2581.       {
  2582.         /* This MUST be overridden, or the class is ill-formed.  */
  2583.         /* For now, we just make it abstract.  */
  2584.         tree fndecl = TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals)), 0);
  2585.         tree vfn;
  2586.  
  2587.         fndecl = copy_node (fndecl);
  2588.         copy_lang_decl (fndecl);
  2589.         DECL_ABSTRACT_VIRTUAL_P (fndecl) = 1;
  2590.         /* Make sure we search for it later. */
  2591.         if (! CLASSTYPE_ABSTRACT_VIRTUALS (t))
  2592.           CLASSTYPE_ABSTRACT_VIRTUALS (t) = error_mark_node;
  2593.  
  2594.         vfn = build1 (ADDR_EXPR, vfunc_ptr_type_node, fndecl);
  2595.         TREE_CONSTANT (vfn) = 1;
  2596.         
  2597.         /* We can use integer_zero_node, as we will will core dump
  2598.            if this is used anyway. */
  2599.         TREE_VALUE (virtuals) = build_vtable_entry (integer_zero_node, vfn);
  2600.       }
  2601.     }
  2602.       virtuals = TREE_CHAIN (virtuals);
  2603.       old_virtuals = TREE_CHAIN (old_virtuals);
  2604.     }
  2605.  
  2606.   /* Let's reuse the old vtable. */
  2607.   if (choose == REUSE_OLD)
  2608.     {
  2609.       BINFO_VTABLE (binfo) = BINFO_VTABLE (old);
  2610.       BINFO_VIRTUALS (binfo) = BINFO_VIRTUALS (old);
  2611.     }
  2612. }
  2613.  
  2614. /* Merge in overrides for virtual bases.
  2615.    BINFO is the hierarchy we want to modify, and OLD has the potential
  2616.    overrides.  */
  2617. static void
  2618. merge_overrides (binfo, old, do_self, t)
  2619.      tree binfo, old, t;
  2620.      int do_self;
  2621. {
  2622.   tree binfos = BINFO_BASETYPES (binfo);
  2623.   tree old_binfos = BINFO_BASETYPES (old);
  2624.   int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
  2625.  
  2626.   /* Should we use something besides CLASSTYPE_VFIELDS? */
  2627.   if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
  2628.     {
  2629.       override_one_vtable (binfo, old, t);
  2630.     }
  2631.  
  2632.   for (i = 0; i < n_baselinks; i++)
  2633.     {
  2634.       tree base_binfo = TREE_VEC_ELT (binfos, i);
  2635.       tree old_base_binfo = TREE_VEC_ELT (old_binfos, i);
  2636.       int is_not_base_vtable =
  2637.     i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
  2638.       if (! TREE_VIA_VIRTUAL (base_binfo))
  2639.     merge_overrides (base_binfo, old_base_binfo, is_not_base_vtable, t);
  2640.     }
  2641. }
  2642.  
  2643. /* Create a RECORD_TYPE or UNION_TYPE node for a C struct or union declaration
  2644.    (or C++ class declaration).
  2645.  
  2646.    For C++, we must handle the building of derived classes.
  2647.    Also, C++ allows static class members.  The way that this is
  2648.    handled is to keep the field name where it is (as the DECL_NAME
  2649.    of the field), and place the overloaded decl in the DECL_FIELD_BITPOS
  2650.    of the field.  layout_record and layout_union will know about this.
  2651.  
  2652.    More C++ hair: inline functions have text in their
  2653.    DECL_PENDING_INLINE_INFO nodes which must somehow be parsed into
  2654.    meaningful tree structure.  After the struct has been laid out, set
  2655.    things up so that this can happen.
  2656.  
  2657.    And still more: virtual functions.  In the case of single inheritance,
  2658.    when a new virtual function is seen which redefines a virtual function
  2659.    from the base class, the new virtual function is placed into
  2660.    the virtual function table at exactly the same address that
  2661.    it had in the base class.  When this is extended to multiple
  2662.    inheritance, the same thing happens, except that multiple virtual
  2663.    function tables must be maintained.  The first virtual function
  2664.    table is treated in exactly the same way as in the case of single
  2665.    inheritance.  Additional virtual function tables have different
  2666.    DELTAs, which tell how to adjust `this' to point to the right thing.
  2667.  
  2668.    LIST_OF_FIELDLISTS is just that.  The elements of the list are
  2669.    TREE_LIST elements, whose TREE_PURPOSE field tells what access
  2670.    the list has, and the TREE_VALUE slot gives the actual fields.
  2671.  
  2672.    If flag_all_virtual == 1, then we lay all functions into
  2673.    the virtual function table, as though they were declared
  2674.    virtual.  Constructors do not lay down in the virtual function table.
  2675.  
  2676.    If flag_all_virtual == 2, then we lay all functions into
  2677.    the virtual function table, such that virtual functions
  2678.    occupy a space by themselves, and then all functions
  2679.    of the class occupy a space by themselves.  This is illustrated
  2680.    in the following diagram:
  2681.  
  2682.    class A; class B : A;
  2683.  
  2684.     Class A's vtbl:            Class B's vtbl:
  2685.     --------------------------------------------------------------------
  2686.    | A's virtual functions|        | B's virtual functions        |
  2687.    |              |        | (may inherit some from A).    |
  2688.     --------------------------------------------------------------------
  2689.    | All of A's functions |        | All of A's functions        |
  2690.    | (such as a->A::f).      |        | (such as b->A::f)        |
  2691.     --------------------------------------------------------------------
  2692.                     | B's new virtual functions    |
  2693.                     | (not defined in A.)        |
  2694.                      -------------------------------
  2695.                     | All of B's functions        |
  2696.                     | (such as b->B::f)        |
  2697.                      -------------------------------
  2698.  
  2699.    this allows the program to make references to any function, virtual
  2700.    or otherwise in a type-consistent manner.  */
  2701.  
  2702. tree
  2703. finish_struct (t, list_of_fieldlists, warn_anon)
  2704.      tree t;
  2705.      tree list_of_fieldlists;
  2706.      int warn_anon;
  2707. {
  2708.   extern int interface_only, interface_unknown;
  2709.  
  2710.   int old;
  2711.   int round_up_size = 1;
  2712.  
  2713.   enum tree_code code = TREE_CODE (t);
  2714.   register tree x, last_x, method_vec;
  2715.   int needs_virtual_dtor;
  2716.   tree name = TYPE_NAME (t), fields, fn_fields, *tail;
  2717.   tree *tail_user_methods = &CLASSTYPE_METHODS (t);
  2718.   enum access_type access;
  2719.   int all_virtual;
  2720.   int has_virtual;
  2721.   int max_has_virtual;
  2722.   tree pending_virtuals = NULL_TREE;
  2723.   tree abstract_virtuals = NULL_TREE;
  2724.   tree vfield;
  2725.   tree vfields;
  2726.   int cant_have_default_ctor;
  2727.   int cant_have_const_ctor;
  2728.   int cant_synth_copy_ctor;
  2729.   int cant_synth_asn_ref;
  2730.   int no_const_asn_ref;
  2731.  
  2732.   /* The index of the first base class which has virtual
  2733.      functions.  Only applied to non-virtual baseclasses.  */
  2734.   int first_vfn_base_index;
  2735.  
  2736.   int n_baseclasses;
  2737.   int any_default_members = 0;
  2738.   int const_sans_init = 0;
  2739.   int ref_sans_init = 0;
  2740.   int nonprivate_method = 0;
  2741.   tree t_binfo = TYPE_BINFO (t);
  2742.   tree access_decls = NULL_TREE;
  2743.  
  2744.   if (TREE_CODE (name) == TYPE_DECL)
  2745.     {
  2746. #if 0                /* Maybe later.  -jason  */
  2747.       struct tinst_level *til = tinst_for_decl();
  2748.  
  2749.       if (til)
  2750.     {
  2751.       DECL_SOURCE_FILE (name) = til->file;
  2752.       if (DECL_SOURCE_LINE (name))
  2753.         DECL_SOURCE_LINE (name) = til->line;
  2754.     }
  2755.       else
  2756. #endif
  2757.     {
  2758.       extern int lineno;
  2759.       
  2760.       DECL_SOURCE_FILE (name) = input_filename;
  2761.       /* For TYPE_DECL that are not typedefs (those marked with a line
  2762.          number of zero, we don't want to mark them as real typedefs.
  2763.          If this fails one needs to make sure real typedefs have a
  2764.          previous line number, even if it is wrong, that way the below
  2765.          will fill in the right line number.  (mrs) */
  2766.       if (DECL_SOURCE_LINE (name))
  2767.         DECL_SOURCE_LINE (name) = lineno;
  2768.       CLASSTYPE_SOURCE_LINE (t) = lineno;
  2769.     }
  2770.       name = DECL_NAME (name);
  2771.     }
  2772.  
  2773.   if (warn_anon && code != UNION_TYPE && ANON_AGGRNAME_P (name))
  2774.     pedwarn ("anonymous class type not used to declare any objects");
  2775.  
  2776.   if (TYPE_SIZE (t))
  2777.     {
  2778.       if (IS_AGGR_TYPE (t))
  2779.     cp_error ("redefinition of `%#T'", t);
  2780.       else
  2781.     my_friendly_abort (172);
  2782.       popclass (0);
  2783.       return t;
  2784.     }
  2785.  
  2786.   /* Append the fields we need for constructing signature tables.  */
  2787.   if (IS_SIGNATURE (t))
  2788.     append_signature_fields (list_of_fieldlists);
  2789.  
  2790.   GNU_xref_decl (current_function_decl, t);
  2791.  
  2792.   /* If this type was previously laid out as a forward reference,
  2793.      make sure we lay it out again.  */
  2794.  
  2795.   TYPE_SIZE (t) = NULL_TREE;
  2796.   CLASSTYPE_GOT_SEMICOLON (t) = 0;
  2797.  
  2798. #if 0
  2799.   /* This is in general too late to do this.  I moved the main case up to
  2800.      left_curly, what else needs to move?  */
  2801.   if (! IS_SIGNATURE (t))
  2802.     {
  2803.       my_friendly_assert (CLASSTYPE_INTERFACE_ONLY (t) == interface_only, 999);
  2804.       my_friendly_assert (CLASSTYPE_INTERFACE_KNOWN (t) == ! interface_unknown, 999);
  2805.     }
  2806. #endif
  2807.  
  2808. #if 0
  2809.   if (flag_rtti)
  2810.     build_t_desc (t, 0);
  2811. #endif
  2812.  
  2813.   TYPE_BINFO (t) = NULL_TREE;
  2814.  
  2815.   old = suspend_momentary ();
  2816.  
  2817.   /* Install struct as DECL_FIELD_CONTEXT of each field decl.
  2818.      Also process specified field sizes.
  2819.      Set DECL_FIELD_SIZE to the specified size, or 0 if none specified.
  2820.      The specified size is found in the DECL_INITIAL.
  2821.      Store 0 there, except for ": 0" fields (so we can find them
  2822.      and delete them, below).  */
  2823.  
  2824.   if (t_binfo && BINFO_BASETYPES (t_binfo))
  2825.     n_baseclasses = TREE_VEC_LENGTH (BINFO_BASETYPES (t_binfo));
  2826.   else
  2827.     n_baseclasses = 0;
  2828.  
  2829.   if (n_baseclasses > 0)
  2830.     {
  2831.       struct base_info base_info;
  2832.  
  2833.       /* If using multiple inheritance, this may cause variants of our
  2834.      basetypes to be used (instead of their canonical forms).  */
  2835.       fields = layout_basetypes (t, BINFO_BASETYPES (t_binfo));
  2836.       last_x = tree_last (fields);
  2837.  
  2838.       first_vfn_base_index = finish_base_struct (t, &base_info, t_binfo);
  2839.       /* Remember where we got our vfield from */
  2840.       CLASSTYPE_VFIELD_PARENT (t) = first_vfn_base_index;
  2841.       has_virtual = base_info.has_virtual;
  2842.       max_has_virtual = base_info.max_has_virtual;
  2843.       CLASSTYPE_N_SUPERCLASSES (t) += base_info.n_ancestors;
  2844.       vfield = base_info.vfield;
  2845.       vfields = base_info.vfields;
  2846.       cant_have_default_ctor = base_info.cant_have_default_ctor;
  2847.       cant_have_const_ctor = base_info.cant_have_const_ctor;
  2848.       cant_synth_copy_ctor = base_info.cant_synth_copy_ctor;
  2849.       cant_synth_asn_ref = base_info.cant_synth_asn_ref;
  2850.       no_const_asn_ref = base_info.no_const_asn_ref;
  2851.       needs_virtual_dtor = base_info.needs_virtual_dtor;
  2852.       n_baseclasses = TREE_VEC_LENGTH (BINFO_BASETYPES (t_binfo));
  2853.     }
  2854.   else
  2855.     {
  2856.       first_vfn_base_index = -1;
  2857.       has_virtual = 0;
  2858.       max_has_virtual = has_virtual;
  2859.       vfield = NULL_TREE;
  2860.       vfields = NULL_TREE;
  2861.       fields = NULL_TREE;
  2862.       last_x = NULL_TREE;
  2863.       cant_have_default_ctor = 0;
  2864.       cant_have_const_ctor = 0;
  2865.       cant_synth_copy_ctor = 0;
  2866.       cant_synth_asn_ref = 0;
  2867.       no_const_asn_ref = 0;
  2868.       needs_virtual_dtor = 0;
  2869.     }
  2870.  
  2871. #if 0
  2872.   /* Both of these should be done before now.  */
  2873.   if (write_virtuals == 3 && CLASSTYPE_INTERFACE_KNOWN (t)
  2874.       && ! IS_SIGNATURE (t))
  2875.     {
  2876.       my_friendly_assert (CLASSTYPE_INTERFACE_ONLY (t) == interface_only, 999);
  2877.       my_friendly_assert (CLASSTYPE_VTABLE_NEEDS_WRITING (t) == ! interface_only, 999);
  2878.     }
  2879. #endif
  2880.  
  2881.   /* The three of these are approximations which may later be
  2882.      modified.  Needed at this point to make add_virtual_function
  2883.      and modify_vtable_entries work.  */
  2884.   TREE_CHAIN (t_binfo) = TYPE_BINFO (t);
  2885.   TYPE_BINFO (t) = t_binfo;
  2886.   CLASSTYPE_VFIELDS (t) = vfields;
  2887.   CLASSTYPE_VFIELD (t) = vfield;
  2888.  
  2889.   tail = &fn_fields;
  2890.   if (last_x && list_of_fieldlists)
  2891.     TREE_CHAIN (last_x) = TREE_VALUE (list_of_fieldlists);
  2892.  
  2893.   if (IS_SIGNATURE (t))
  2894.     all_virtual = 0;
  2895.   else if (flag_all_virtual == 1 && TYPE_OVERLOADS_METHOD_CALL_EXPR (t))
  2896.     all_virtual = 1;
  2897.   else
  2898.     all_virtual = 0;
  2899.  
  2900.   /* For signatures, we made all methods `public' in the parser and
  2901.      reported an error if a access specifier was used.  */
  2902.   if (CLASSTYPE_DECLARED_CLASS (t) == 0)
  2903.     {
  2904.       nonprivate_method = 1;
  2905.       if (list_of_fieldlists
  2906.       && TREE_PURPOSE (list_of_fieldlists) == (tree)access_default)
  2907.     TREE_PURPOSE (list_of_fieldlists) = (tree)access_public;
  2908.     }
  2909.   else if (list_of_fieldlists
  2910.        && TREE_PURPOSE (list_of_fieldlists) == (tree)access_default)
  2911.     TREE_PURPOSE (list_of_fieldlists) = (tree)access_private;
  2912.  
  2913.   while (list_of_fieldlists)
  2914.     {
  2915.       access = (enum access_type)TREE_PURPOSE (list_of_fieldlists);
  2916.  
  2917.       for (x = TREE_VALUE (list_of_fieldlists); x; x = TREE_CHAIN (x))
  2918.     {
  2919.       TREE_PRIVATE (x) = access == access_private;
  2920.       TREE_PROTECTED (x) = access == access_protected;
  2921.       GNU_xref_member (current_class_name, x);
  2922.  
  2923.           if (TREE_CODE (x) == TYPE_DECL)
  2924.             {
  2925.           /* Make sure we set this up.  In find_scoped_type, it explicitly
  2926.          looks for a TYPE_DECL in the TYPE_FIELDS list.  If we don't
  2927.          do this here, we'll miss including this TYPE_DECL in the
  2928.          list.  */
  2929.           if (! fields)
  2930.         fields = x;
  2931.           last_x = x;
  2932.           continue;
  2933.         }
  2934.  
  2935.       /* Check for inconsistent use of this name in the class body.
  2936.              Enums, types and static vars have already been checked.  */
  2937.       if (TREE_CODE (x) != CONST_DECL && TREE_CODE (x) != VAR_DECL)
  2938.         {
  2939.           tree name = DECL_NAME (x);
  2940.           tree icv;
  2941.  
  2942.           /* Don't get confused by access decls.  */
  2943.           if (name && TREE_CODE (name) == IDENTIFIER_NODE)
  2944.         icv = IDENTIFIER_CLASS_VALUE (name);
  2945.           else
  2946.         icv = NULL_TREE;
  2947.  
  2948.           if (icv
  2949.           /* Don't complain about constructors.  */
  2950.           && name != constructor_name (current_class_type)
  2951.           /* Or inherited names.  */
  2952.           && id_in_current_class (name)
  2953.           /* Or shadowed tags.  */
  2954.           && !(TREE_CODE (icv) == TYPE_DECL
  2955.                && DECL_CONTEXT (icv) == t))
  2956.         {
  2957.           cp_error_at ("declaration of identifier `%D' as `%+#D'",
  2958.                    name, x);
  2959.           cp_error_at ("conflicts with other use in class as `%#D'",
  2960.                    icv);
  2961.         }
  2962.         }
  2963.  
  2964.       if (TREE_CODE (x) == FUNCTION_DECL)
  2965.         {
  2966.           nonprivate_method |= ! TREE_PRIVATE (x);
  2967.  
  2968.           /* If this was an evil function, don't keep it in class.  */
  2969.           if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (x)))
  2970.         continue;
  2971.  
  2972.           if (last_x)
  2973.         TREE_CHAIN (last_x) = TREE_CHAIN (x);
  2974.           /* Link x onto end of fn_fields and CLASSTYPE_METHODS. */
  2975.           *tail = x;
  2976.           tail = &TREE_CHAIN (x);
  2977.           *tail_user_methods = x;
  2978.           tail_user_methods = &DECL_NEXT_METHOD (x);
  2979.  
  2980.           DECL_CLASS_CONTEXT (x) = t;
  2981.  
  2982.           /* Do both of these, even though they're in the same union;
  2983.          if the insn `r' member and the size `i' member are
  2984.          different sizes, as on the alpha, the larger of the two
  2985.          will end up with garbage in it.  */
  2986.           DECL_SAVED_INSNS (x) = NULL_RTX;
  2987.           DECL_FIELD_SIZE (x) = 0;
  2988.  
  2989.           /* The name of the field is the original field name
  2990.          Save this in auxiliary field for later overloading.  */
  2991.           if (DECL_VINDEX (x)
  2992.           || (all_virtual == 1 && ! DECL_CONSTRUCTOR_P (x)))
  2993.         {
  2994.                   pending_virtuals = add_virtual_function (pending_virtuals,
  2995.                                                            &has_virtual, x, t);
  2996.                   if (DECL_ABSTRACT_VIRTUAL_P (x))
  2997.                     abstract_virtuals = tree_cons (NULL_TREE, x, abstract_virtuals);
  2998.         }
  2999.           continue;
  3000.         }
  3001.  
  3002.       /* Handle access declarations.  */
  3003.       if (DECL_NAME (x) && TREE_CODE (DECL_NAME (x)) == SCOPE_REF)
  3004.         {
  3005.           tree fdecl = TREE_OPERAND (DECL_NAME (x), 1);
  3006.  
  3007.           if (last_x)
  3008.         TREE_CHAIN (last_x) = TREE_CHAIN (x);
  3009.           access_decls = tree_cons ((tree) access, fdecl, access_decls);
  3010.           continue;
  3011.         }
  3012.  
  3013.       /* If we've gotten this far, it's a data member, possibly static,
  3014.          or an enumerator. */
  3015.  
  3016.       DECL_FIELD_CONTEXT (x) = t;
  3017.  
  3018.       /* ``A local class cannot have static data members.'' ARM 9.4 */
  3019.       if (current_function_decl && TREE_STATIC (x))
  3020.         cp_error_at ("field `%D' in local class cannot be static", x);
  3021.  
  3022.       /* Perform error checking that did not get done in
  3023.              grokdeclarator.  */
  3024.       if (TREE_CODE (TREE_TYPE (x)) == FUNCTION_TYPE)
  3025.         {
  3026.           cp_error_at ("field `%D' invalidly declared function type",
  3027.             x);
  3028.           TREE_TYPE (x) = build_pointer_type (TREE_TYPE (x));
  3029.         }
  3030.       else if (TREE_CODE (TREE_TYPE (x)) == METHOD_TYPE)
  3031.         {
  3032.           cp_error_at ("field `%D' invalidly declared method type", x);
  3033.           TREE_TYPE (x) = build_pointer_type (TREE_TYPE (x));
  3034.         }
  3035.       else if (TREE_CODE (TREE_TYPE (x)) == OFFSET_TYPE)
  3036.         {
  3037.           cp_error_at ("field `%D' invalidly declared offset type", x);
  3038.           TREE_TYPE (x) = build_pointer_type (TREE_TYPE (x));
  3039.         }
  3040.  
  3041.       if (DECL_NAME (x) == constructor_name (t))
  3042.         cant_have_default_ctor = cant_synth_copy_ctor = 1;
  3043.  
  3044.       if (TREE_TYPE (x) == error_mark_node)
  3045.         continue;
  3046.       
  3047.       if (! fields)
  3048.         fields = x;
  3049.       last_x = x;
  3050.  
  3051.       DECL_SAVED_INSNS (x) = NULL_RTX;
  3052.       DECL_FIELD_SIZE (x) = 0;
  3053.  
  3054.       /* When this goes into scope, it will be a non-local reference.  */
  3055.       DECL_NONLOCAL (x) = 1;
  3056.  
  3057.       if (TREE_CODE (x) == CONST_DECL)
  3058.         continue;
  3059.  
  3060.       if (TREE_CODE (x) == VAR_DECL)
  3061.         {
  3062.           if (TREE_CODE (t) == UNION_TYPE)
  3063.         /* Unions cannot have static members.  */
  3064.         cp_error_at ("field `%D' declared static in union", x);
  3065.           
  3066.           continue;
  3067.         }
  3068.  
  3069.       /* Now it can only be a FIELD_DECL.  */
  3070.  
  3071.       /* If this is of reference type, check if it needs an init.
  3072.          Also do a little ANSI jig if necessary.  */
  3073.       if (TREE_CODE (TREE_TYPE (x)) == REFERENCE_TYPE)
  3074.         {
  3075.           if (DECL_INITIAL (x) == NULL_TREE)
  3076.         ref_sans_init = 1;
  3077.  
  3078.           /* ARM $12.6.2: [A member initializer list] (or, for an
  3079.          aggregate, initialization by a brace-enclosed list) is the
  3080.          only way to initialize nonstatic const and reference
  3081.          members.  */
  3082.           cant_synth_asn_ref = 1;
  3083.           cant_have_default_ctor = 1;
  3084.  
  3085.           if (! TYPE_HAS_CONSTRUCTOR (t) && extra_warnings)
  3086.         {
  3087.           if (DECL_NAME (x))
  3088.             cp_warning_at ("non-static reference `%#D' in class without a constructor", x);
  3089.           else
  3090.             cp_warning_at ("non-static reference in class without a constructor", x);
  3091.         }
  3092.         }
  3093.  
  3094.       /* If any field is const, the structure type is pseudo-const.  */
  3095.       if (TREE_READONLY (x))
  3096.         {
  3097.           C_TYPE_FIELDS_READONLY (t) = 1;
  3098.           if (DECL_INITIAL (x) == NULL_TREE)
  3099.         const_sans_init = 1;
  3100.  
  3101.           /* ARM $12.6.2: [A member initializer list] (or, for an
  3102.          aggregate, initialization by a brace-enclosed list) is the
  3103.          only way to initialize nonstatic const and reference
  3104.          members.  */
  3105.           cant_synth_asn_ref = 1;
  3106.           cant_have_default_ctor = 1;
  3107.  
  3108.           if (! TYPE_HAS_CONSTRUCTOR (t) && !IS_SIGNATURE (t)
  3109.           && extra_warnings)
  3110.         {
  3111.           if (DECL_NAME (x))
  3112.             cp_warning_at ("non-static const member `%#D' in class without a constructor", x);
  3113.           else
  3114.             cp_warning_at ("non-static const member in class without a constructor", x);
  3115.         }
  3116.         }
  3117.       else
  3118.         {
  3119.           /* A field that is pseudo-const makes the structure
  3120.          likewise.  */
  3121.           tree t1 = TREE_TYPE (x);
  3122.           while (TREE_CODE (t1) == ARRAY_TYPE)
  3123.         t1 = TREE_TYPE (t1);
  3124.           if (IS_AGGR_TYPE (t1))
  3125.         {
  3126.           if (C_TYPE_FIELDS_READONLY (t1))
  3127.             C_TYPE_FIELDS_READONLY (t) = 1;
  3128.           if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (t1))
  3129.             const_sans_init = 1;
  3130.         }
  3131.         }
  3132.  
  3133.       /* We set DECL_BIT_FIELD tentatively in grokbitfield.
  3134.          If the type and width are valid, we'll keep it set.
  3135.          Otherwise, the flag is cleared.  */
  3136.       if (DECL_BIT_FIELD (x))
  3137.         {
  3138.           DECL_BIT_FIELD (x) = 0;
  3139.           /* Invalid bit-field size done by grokfield.  */
  3140.           /* Detect invalid bit-field type.  */
  3141.           if (DECL_INITIAL (x)
  3142.           && ! INTEGRAL_TYPE_P (TREE_TYPE (x)))
  3143.         {
  3144.           cp_error_at ("bit-field `%#D' with non-integral type", x);
  3145.           DECL_INITIAL (x) = NULL;
  3146.         }
  3147.  
  3148.           /* Detect and ignore out of range field width.  */
  3149.           if (DECL_INITIAL (x))
  3150.         {
  3151.           register int width = TREE_INT_CST_LOW (DECL_INITIAL (x));
  3152.  
  3153.           if (width < 0)
  3154.             {
  3155.               DECL_INITIAL (x) = NULL;
  3156.               cp_error_at ("negative width in bit-field `%D'", x);
  3157.             }
  3158.           else if (width == 0 && DECL_NAME (x) != 0)
  3159.             {
  3160.               DECL_INITIAL (x) = NULL;
  3161.               cp_error_at ("zero width for bit-field `%D'", x);
  3162.             }
  3163.           else if (width
  3164.                > TYPE_PRECISION (long_long_unsigned_type_node))
  3165.             {
  3166.               /* The backend will dump if you try to use something
  3167.              too big; avoid that.  */
  3168.               DECL_INITIAL (x) = NULL;
  3169.               sorry ("bit-fields larger than %d bits",
  3170.                  TYPE_PRECISION (long_long_unsigned_type_node));
  3171.               cp_error_at ("  in declaration of `%D'", x);
  3172.             }
  3173.           else if (width > TYPE_PRECISION (TREE_TYPE (x))
  3174.                && TREE_CODE (TREE_TYPE (x)) != ENUMERAL_TYPE)
  3175.             {
  3176.               cp_warning_at ("width of `%D' exceeds its type", x);
  3177.             }
  3178.           else if (TREE_CODE (TREE_TYPE (x)) == ENUMERAL_TYPE
  3179.            && ((min_precision (TYPE_MIN_VALUE (TREE_TYPE (x)),
  3180.                    TREE_UNSIGNED (TREE_TYPE (x))) > width)
  3181.            || (min_precision (TYPE_MAX_VALUE (TREE_TYPE (x)),
  3182.                       TREE_UNSIGNED (TREE_TYPE (x))) > width)))
  3183.             {
  3184.               cp_warning_at ("`%D' is too small to hold all values of `%#T'",
  3185.                      x, TREE_TYPE (x));
  3186.             }
  3187.         }
  3188.  
  3189.           /* Process valid field width.  */
  3190.           if (DECL_INITIAL (x))
  3191.         {
  3192.           register int width = TREE_INT_CST_LOW (DECL_INITIAL (x));
  3193.  
  3194.           if (width == 0)
  3195.             {
  3196. #ifdef EMPTY_FIELD_BOUNDARY
  3197.               /* field size 0 => mark following field as "aligned" */
  3198.               if (TREE_CHAIN (x))
  3199.             DECL_ALIGN (TREE_CHAIN (x))
  3200.               = MAX (DECL_ALIGN (TREE_CHAIN (x)), EMPTY_FIELD_BOUNDARY);
  3201.               /* field of size 0 at the end => round up the size.  */
  3202.               else
  3203.             round_up_size = EMPTY_FIELD_BOUNDARY;
  3204. #endif
  3205. #ifdef PCC_BITFIELD_TYPE_MATTERS
  3206.               DECL_ALIGN (x) = MAX (DECL_ALIGN (x),
  3207.                         TYPE_ALIGN (TREE_TYPE (x)));
  3208. #endif
  3209.             }
  3210.           else
  3211.             {
  3212.               DECL_INITIAL (x) = NULL_TREE;
  3213.               DECL_FIELD_SIZE (x) = width;
  3214.               DECL_BIT_FIELD (x) = 1;
  3215.               /* Traditionally a bit field is unsigned
  3216.              even if declared signed.  */
  3217.               if (flag_traditional
  3218.               && TREE_CODE (TREE_TYPE (x)) == INTEGER_TYPE)
  3219.             TREE_TYPE (x) = unsigned_type_node;
  3220.             }
  3221.         }
  3222.           else
  3223.         /* Non-bit-fields are aligned for their type.  */
  3224.         DECL_ALIGN (x) = MAX (DECL_ALIGN (x), TYPE_ALIGN (TREE_TYPE (x)));
  3225.         }
  3226.       else
  3227.         {
  3228.           tree type = TREE_TYPE (x);
  3229.  
  3230.           if (TREE_CODE (type) == ARRAY_TYPE)
  3231.         type = TREE_TYPE (type);
  3232.  
  3233.           if (TYPE_LANG_SPECIFIC (type) && ! ANON_UNION_P (x)
  3234.           && ! TYPE_PTRMEMFUNC_P (type))
  3235.         {
  3236.           /* Never let anything with uninheritable virtuals
  3237.              make it through without complaint.  */
  3238.           if (CLASSTYPE_ABSTRACT_VIRTUALS (type))
  3239.             abstract_virtuals_error (x, type);
  3240.               
  3241.           /* Don't let signatures make it through either.  */
  3242.           if (IS_SIGNATURE (type))
  3243.             signature_error (x, type);
  3244.               
  3245.           if (code == UNION_TYPE)
  3246.             {
  3247.               char *fie = NULL;
  3248.               if (TYPE_NEEDS_CONSTRUCTING (type))
  3249.             fie = "constructor";
  3250.               else if (TYPE_NEEDS_DESTRUCTOR (type))
  3251.             fie = "destructor";
  3252.               else if (TYPE_HAS_REAL_ASSIGNMENT (type))
  3253.             fie = "assignment operator";
  3254.               if (fie)
  3255.             cp_error_at ("member `%#D' with %s not allowed in union", x,
  3256.                      fie);
  3257.             }
  3258.           else
  3259.             {
  3260.               TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (type);
  3261.               TYPE_NEEDS_DESTRUCTOR (t) |= TYPE_NEEDS_DESTRUCTOR (type);
  3262.               TYPE_HAS_COMPLEX_ASSIGN_REF (t) |= TYPE_HAS_COMPLEX_ASSIGN_REF (type);
  3263.               TYPE_HAS_COMPLEX_INIT_REF (t) |= TYPE_HAS_COMPLEX_INIT_REF (type);
  3264.             }
  3265.  
  3266.           if (! TYPE_HAS_INIT_REF (type)
  3267.               || (TYPE_HAS_NONPUBLIC_CTOR (type)
  3268.               && ! is_friend (t, type)))
  3269.             cant_synth_copy_ctor = 1;
  3270.           else if (!TYPE_HAS_CONST_INIT_REF (type))
  3271.             cant_have_const_ctor = 1;
  3272.  
  3273.           if (! TYPE_HAS_ASSIGN_REF (type)
  3274.               || (TYPE_HAS_NONPUBLIC_ASSIGN_REF (type)
  3275.               && ! is_friend (t, type)))
  3276.             cant_synth_asn_ref = 1;
  3277.           else if (!TYPE_HAS_CONST_ASSIGN_REF (type))
  3278.             no_const_asn_ref = 1;
  3279.  
  3280.           if (TYPE_HAS_CONSTRUCTOR (type)
  3281.               && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (type))
  3282.             {
  3283.               cant_have_default_ctor = 1;
  3284. #if 0
  3285.               /* This is wrong for aggregates.  */
  3286.               if (! TYPE_HAS_CONSTRUCTOR (t))
  3287.             {
  3288.               if (DECL_NAME (x))
  3289.                 cp_pedwarn_at ("member `%#D' with only non-default constructor", x);
  3290.               else
  3291.                 cp_pedwarn_at ("member with only non-default constructor", x);
  3292.               cp_pedwarn_at ("in class without a constructor",
  3293.                      x);
  3294.             }
  3295. #endif
  3296.             }
  3297.         }
  3298.           if (DECL_INITIAL (x) != NULL_TREE)
  3299.         {
  3300.           /* `build_class_init_list' does not recognize
  3301.                      non-FIELD_DECLs.  */
  3302.           if (code == UNION_TYPE && any_default_members != 0)
  3303.             cp_error_at ("multiple fields in union `%T' initialized");
  3304.           any_default_members = 1;
  3305.         }
  3306.         }
  3307.     }
  3308.       list_of_fieldlists = TREE_CHAIN (list_of_fieldlists);
  3309.       /* link the tail while we have it! */
  3310.       if (last_x)
  3311.     {
  3312.       TREE_CHAIN (last_x) = NULL_TREE;
  3313.  
  3314.       if (list_of_fieldlists
  3315.           && TREE_VALUE (list_of_fieldlists)
  3316.           && TREE_CODE (TREE_VALUE (list_of_fieldlists)) != FUNCTION_DECL)
  3317.         TREE_CHAIN (last_x) = TREE_VALUE (list_of_fieldlists);
  3318.     }
  3319.     }
  3320.  
  3321.   /* If this type has any constant members which did not come
  3322.      with their own initialization, mark that fact here.  It is
  3323.      not an error here, since such types can be saved either by their
  3324.      constructors, or by fortuitous initialization.  */
  3325.   CLASSTYPE_READONLY_FIELDS_NEED_INIT (t) = const_sans_init;
  3326.   CLASSTYPE_REF_FIELDS_NEED_INIT (t) = ref_sans_init;
  3327.   CLASSTYPE_ABSTRACT_VIRTUALS (t) = abstract_virtuals;
  3328.  
  3329.   /* Synthesize any needed methods.  Note that methods will be synthesized
  3330.      for anonymous unions; grok_x_components undoes that.  */
  3331.  
  3332.   if (TYPE_NEEDS_DESTRUCTOR (t) && !TYPE_HAS_DESTRUCTOR (t)
  3333.       && !IS_SIGNATURE (t))
  3334.     {
  3335.       /* Here we must cons up a destructor on the fly.  */
  3336.       tree dtor = cons_up_default_function (t, name, needs_virtual_dtor != 0);
  3337.  
  3338.       /* If we couldn't make it work, then pretend we didn't need it.  */
  3339.       if (dtor == void_type_node)
  3340.     TYPE_NEEDS_DESTRUCTOR (t) = 0;
  3341.       else
  3342.     {
  3343.       /* Link dtor onto end of fn_fields. */
  3344.       *tail = dtor;
  3345.       tail = &TREE_CHAIN (dtor);
  3346.  
  3347.       if (DECL_VINDEX (dtor) == NULL_TREE
  3348.           && (needs_virtual_dtor
  3349.           || pending_virtuals != NULL_TREE
  3350.           || pending_hard_virtuals != NULL_TREE))
  3351.         DECL_VINDEX (dtor) = error_mark_node;
  3352.       if (DECL_VINDEX (dtor))
  3353.         pending_virtuals = add_virtual_function (pending_virtuals,
  3354.                              &has_virtual, dtor, t);
  3355.       nonprivate_method = 1;
  3356.     }
  3357.     }
  3358.  
  3359.   *tail = NULL_TREE;
  3360.   *tail_user_methods = NULL_TREE;
  3361.  
  3362.   TYPE_NEEDS_DESTRUCTOR (t) |= TYPE_HAS_DESTRUCTOR (t);
  3363.   if (flag_rtti && (max_has_virtual > 0 || needs_virtual_dtor) && 
  3364.     has_virtual == 0)
  3365.     has_virtual = 1;
  3366.  
  3367.   if (! fn_fields)
  3368.     nonprivate_method = 1;
  3369.  
  3370.   TYPE_HAS_COMPLEX_INIT_REF (t)
  3371.     |= (TYPE_HAS_INIT_REF (t) || TYPE_USES_VIRTUAL_BASECLASSES (t)
  3372.     || any_default_members);
  3373.   TYPE_NEEDS_CONSTRUCTING (t)
  3374.     |= (TYPE_HAS_CONSTRUCTOR (t) || TYPE_USES_VIRTUAL_BASECLASSES (t)
  3375.     || has_virtual || any_default_members || first_vfn_base_index >= 0);
  3376.  
  3377.   /* ARM $12.1: A default constructor will be generated for a class X
  3378.      only if no constructor has been declared for class X.  So we
  3379.      check TYPE_HAS_CONSTRUCTOR also, to make sure we don't generate
  3380.      one if they declared a constructor in this class.  */
  3381.   if (! TYPE_HAS_CONSTRUCTOR (t) && ! cant_have_default_ctor
  3382.       && ! IS_SIGNATURE (t))
  3383.     {
  3384.       tree default_fn = cons_up_default_function (t, name, 2);
  3385.       TREE_CHAIN (default_fn) = fn_fields;
  3386.       fn_fields = default_fn;
  3387.     }
  3388.  
  3389.   /* Create default copy constructor, if needed.  */
  3390.   if (! TYPE_HAS_INIT_REF (t) && ! cant_synth_copy_ctor
  3391.       && ! IS_SIGNATURE (t))
  3392.     {
  3393.       /* ARM 12.18: You get either X(X&) or X(const X&), but
  3394.      not both.  --Chip  */
  3395.       tree default_fn = cons_up_default_function (t, name,
  3396.                           3 + cant_have_const_ctor);
  3397.       TREE_CHAIN (default_fn) = fn_fields;
  3398.       fn_fields = default_fn;
  3399.     }
  3400.  
  3401.   TYPE_HAS_REAL_ASSIGNMENT (t) |= TYPE_HAS_ASSIGNMENT (t);
  3402.   TYPE_HAS_REAL_ASSIGN_REF (t) |= TYPE_HAS_ASSIGN_REF (t);
  3403.   TYPE_HAS_COMPLEX_ASSIGN_REF (t)
  3404.     |= TYPE_HAS_ASSIGN_REF (t) || TYPE_USES_VIRTUAL_BASECLASSES (t);
  3405.  
  3406.   if (! TYPE_HAS_ASSIGN_REF (t) && ! cant_synth_asn_ref
  3407.       && ! IS_SIGNATURE (t))
  3408.     {
  3409.       tree default_fn = cons_up_default_function (t, name,
  3410.                           5 + no_const_asn_ref);
  3411.       TREE_CHAIN (default_fn) = fn_fields;
  3412.       fn_fields = default_fn;
  3413.     }
  3414.  
  3415.   if (fn_fields)
  3416.     {
  3417.       method_vec = finish_struct_methods (t, fn_fields, nonprivate_method);
  3418.  
  3419.       if (TYPE_HAS_CONSTRUCTOR (t)
  3420.       && CLASSTYPE_FRIEND_CLASSES (t) == NULL_TREE
  3421.       && DECL_FRIENDLIST (TYPE_NAME (t)) == NULL_TREE)
  3422.     {
  3423.       int nonprivate_ctor = 0;
  3424.       tree ctor;
  3425.  
  3426.       for (ctor = TREE_VEC_ELT (method_vec, 0);
  3427.            ctor;
  3428.            ctor = DECL_CHAIN (ctor))
  3429.         if (! TREE_PRIVATE (ctor))
  3430.           {
  3431.         nonprivate_ctor = 1;
  3432.         break;
  3433.           }
  3434.  
  3435.       if (nonprivate_ctor == 0 && warn_ctor_dtor_privacy)
  3436.         cp_warning ("`%#T' only defines private constructors and has no friends",
  3437.             t);
  3438.     }
  3439.     }
  3440.   else
  3441.     {
  3442.       method_vec = 0;
  3443.  
  3444.       /* Just in case these got accidentally
  3445.      filled in by syntax errors.  */
  3446.       TYPE_HAS_CONSTRUCTOR (t) = 0;
  3447.       TYPE_HAS_DESTRUCTOR (t) = 0;
  3448.     }
  3449.  
  3450.   {
  3451.     int n_methods = method_vec ? TREE_VEC_LENGTH (method_vec) : 0;
  3452.     
  3453.     for (access_decls = nreverse (access_decls); access_decls;
  3454.      access_decls = TREE_CHAIN (access_decls))
  3455.       {
  3456.     tree fdecl = TREE_VALUE (access_decls);
  3457.     tree flist = NULL_TREE;
  3458.     tree name;
  3459.     enum access_type access = (enum access_type)TREE_PURPOSE(access_decls);
  3460.     int i = TREE_VEC_ELT (method_vec, 0) ? 0 : 1;
  3461.     tree tmp;
  3462.  
  3463.     if (TREE_CODE (fdecl) == TREE_LIST)
  3464.       {
  3465.         flist = fdecl;
  3466.         fdecl = TREE_VALUE (flist);
  3467.       }
  3468.  
  3469.     name = DECL_NAME (fdecl);
  3470.  
  3471.     for (; i < n_methods; i++)
  3472.       if (DECL_NAME (TREE_VEC_ELT (method_vec, i)) == name)
  3473.         {
  3474.           cp_error ("cannot adjust access to `%#D' in `%#T'", fdecl, t);
  3475.           cp_error_at ("  because of local method `%#D' with same name",
  3476.                TREE_VEC_ELT (method_vec, i));
  3477.           fdecl = NULL_TREE;
  3478.           break;
  3479.         }
  3480.  
  3481.     if (! fdecl)
  3482.       continue;
  3483.     
  3484.     for (tmp = fields; tmp; tmp = TREE_CHAIN (tmp))
  3485.       if (DECL_NAME (tmp) == name)
  3486.         {
  3487.           cp_error ("cannot adjust access to `%#D' in `%#T'", fdecl, t);
  3488.           cp_error_at ("  because of local field `%#D' with same name", tmp);
  3489.           fdecl = NULL_TREE;
  3490.           break;
  3491.         }
  3492.  
  3493.     if (!fdecl)
  3494.       continue;
  3495.     
  3496.     /* Make type T see field decl FDECL with access ACCESS.*/
  3497.     if (flist)
  3498.       {
  3499.         fdecl = TREE_VALUE (flist);
  3500.         while (fdecl)
  3501.           {
  3502.         if (alter_access (t, fdecl, access) == 0)
  3503.           break;
  3504.         fdecl = DECL_CHAIN (fdecl);
  3505.           }
  3506.       }
  3507.     else
  3508.       alter_access (t, fdecl, access);
  3509.       }
  3510.     
  3511.   }
  3512.  
  3513.   if (vfield == NULL_TREE && has_virtual)
  3514.     {
  3515.       /* We build this decl with ptr_type_node, and
  3516.      change the type when we know what it should be.  */
  3517.       vfield = build_lang_field_decl (FIELD_DECL, get_vfield_name (t),
  3518.                       ptr_type_node);
  3519.       /* If you change any of the below, take a look at all the
  3520.      other VFIELD_BASEs and VTABLE_BASEs in the code, and change
  3521.      them too. */
  3522.       DECL_ASSEMBLER_NAME (vfield) = get_identifier (VFIELD_BASE);
  3523.       CLASSTYPE_VFIELD (t) = vfield;
  3524.       DECL_VIRTUAL_P (vfield) = 1;
  3525.       DECL_FIELD_CONTEXT (vfield) = t;
  3526.       DECL_CLASS_CONTEXT (vfield) = t;
  3527.       DECL_FCONTEXT (vfield) = t;
  3528.       DECL_SAVED_INSNS (vfield) = NULL_RTX;
  3529.       DECL_FIELD_SIZE (vfield) = 0;
  3530.       DECL_ALIGN (vfield) = TYPE_ALIGN (ptr_type_node);
  3531.       if (CLASSTYPE_RTTI (t))
  3532.     {
  3533.       /* vfield is always first entry in structure.  */
  3534.       TREE_CHAIN (vfield) = fields;
  3535.       fields = vfield;
  3536.     }
  3537.       else if (last_x)
  3538.     {
  3539.       my_friendly_assert (TREE_CHAIN (last_x) == NULL_TREE, 175);
  3540.       TREE_CHAIN (last_x) = vfield;
  3541.       last_x = vfield;
  3542.     }
  3543.       else
  3544.     fields = vfield;
  3545.       vfields = chainon (vfields, CLASSTYPE_AS_LIST (t));
  3546.     }
  3547.  
  3548.   /* Now DECL_INITIAL is null on all members except for zero-width bit-fields.
  3549.      And they have already done their work.
  3550.  
  3551.      C++: maybe we will support default field initialization some day...  */
  3552.  
  3553.   /* Delete all zero-width bit-fields from the front of the fieldlist */
  3554.   while (fields && DECL_BIT_FIELD (fields)
  3555.      && DECL_INITIAL (fields))
  3556.     fields = TREE_CHAIN (fields);
  3557.   /* Delete all such fields from the rest of the fields.  */
  3558.   for (x = fields; x;)
  3559.     {
  3560.       if (TREE_CHAIN (x) && DECL_BIT_FIELD (TREE_CHAIN (x))
  3561.       && DECL_INITIAL (TREE_CHAIN (x)))
  3562.     TREE_CHAIN (x) = TREE_CHAIN (TREE_CHAIN (x));
  3563.       else
  3564.     x = TREE_CHAIN (x);
  3565.     }
  3566.   /* Delete all duplicate fields from the fields */
  3567.   delete_duplicate_fields (fields);
  3568.  
  3569.   /* Catch function/field name conflict.  We don't need to do this for a
  3570.      signature, since it can only contain the fields constructed in
  3571.      append_signature_fields.  */
  3572.   if (! IS_SIGNATURE (t))
  3573.     {
  3574.       int n_methods = method_vec ? TREE_VEC_LENGTH (method_vec) : 0;
  3575.       for (x = fields; x; x = TREE_CHAIN (x))
  3576.     {
  3577.       tree name = DECL_NAME (x);
  3578.       int i = /*TREE_VEC_ELT (method_vec, 0) ? 0 : */ 1;
  3579.       for (; i < n_methods; ++i)
  3580.         if (DECL_NAME (TREE_VEC_ELT (method_vec, i)) == name)
  3581.           {
  3582.         cp_error_at ("data member `%#D' conflicts with", x);
  3583.         cp_error_at ("function member `%#D'",
  3584.                  TREE_VEC_ELT (method_vec, i));
  3585.         break;
  3586.           }
  3587.     }
  3588.     }
  3589.  
  3590.   /* Now we have the final fieldlist for the data fields.  Record it,
  3591.      then lay out the structure or union (including the fields).  */
  3592.  
  3593.   TYPE_FIELDS (t) = fields;
  3594.  
  3595.   /* If there's a :0 field at the end, round the size to the
  3596.      EMPTY_FIELD_BOUNDARY.  */
  3597.   TYPE_ALIGN (t) = round_up_size;
  3598.  
  3599.   /* Pass layout information about base classes to layout_type, if any.  */
  3600.   if (n_baseclasses)
  3601.     {
  3602.       tree pseudo_basetype = TREE_TYPE (base_layout_decl);
  3603.  
  3604.       TREE_CHAIN (base_layout_decl) = TYPE_FIELDS (t);
  3605.       TYPE_FIELDS (t) = base_layout_decl;
  3606.  
  3607.       TYPE_SIZE (pseudo_basetype) = CLASSTYPE_SIZE (t);
  3608.       TYPE_MODE (pseudo_basetype) = TYPE_MODE (t);
  3609.       TYPE_ALIGN (pseudo_basetype) = CLASSTYPE_ALIGN (t);
  3610.       DECL_ALIGN (base_layout_decl) = TYPE_ALIGN (pseudo_basetype);
  3611.       /* Don't re-use old size. */
  3612.       DECL_SIZE (base_layout_decl) = NULL_TREE;
  3613.     }
  3614.  
  3615.   layout_type (t);
  3616.  
  3617.   {
  3618.     tree field;
  3619.     for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
  3620.       {
  3621.     if (TREE_STATIC (field))
  3622.       continue;
  3623.     if (TREE_CODE (field) != FIELD_DECL)
  3624.       continue;
  3625.  
  3626.     /* If this field is an anonymous union,
  3627.        give each union-member the same position as the union has.
  3628.  
  3629.        ??? This is a real kludge because it makes the structure
  3630.        of the types look strange.  This feature is only used by
  3631.        C++, which should have build_component_ref build two
  3632.        COMPONENT_REF operations, one for the union and one for
  3633.        the inner field.  We set the offset of this field to zero
  3634.        so that either the old or the correct method will work.
  3635.        Setting DECL_FIELD_CONTEXT is wrong unless the inner fields are
  3636.        moved into the type of this field, but nothing seems to break
  3637.        by doing this.  */
  3638.  
  3639.     if (DECL_NAME (field) == NULL_TREE
  3640.         && TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)
  3641.       {
  3642.         tree uelt = TYPE_FIELDS (TREE_TYPE (field));
  3643.         for (; uelt; uelt = TREE_CHAIN (uelt))
  3644.           {
  3645.         if (TREE_CODE (uelt) != FIELD_DECL)
  3646.           continue;
  3647.  
  3648.         DECL_FIELD_CONTEXT (uelt) = DECL_FIELD_CONTEXT (field);
  3649.         DECL_FIELD_BITPOS (uelt) = DECL_FIELD_BITPOS (field);
  3650.           }
  3651.  
  3652.         DECL_FIELD_BITPOS (field) = integer_zero_node;
  3653.       }
  3654.       }
  3655.   }
  3656.  
  3657.   if (n_baseclasses)
  3658.     TYPE_FIELDS (t) = TREE_CHAIN (TYPE_FIELDS (t));
  3659.  
  3660.   /* C++: do not let empty structures exist.  */
  3661.   if (integer_zerop (TYPE_SIZE (t)))
  3662.     TYPE_SIZE (t) = TYPE_SIZE (char_type_node);
  3663.  
  3664.   /* Set the TYPE_DECL for this type to contain the right
  3665.      value for DECL_OFFSET, so that we can use it as part
  3666.      of a COMPONENT_REF for multiple inheritance.  */
  3667.  
  3668.   if (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL)
  3669.     layout_decl (TYPE_NAME (t), 0);
  3670.  
  3671.   /* Now fix up any virtual base class types that we left lying
  3672.      around.  We must get these done before we try to lay out the
  3673.      virtual function table.  */
  3674.   doing_hard_virtuals = 1;
  3675.   pending_hard_virtuals = nreverse (pending_hard_virtuals);
  3676.  
  3677.   if (TYPE_USES_VIRTUAL_BASECLASSES (t))
  3678.     {
  3679.       tree vbases;
  3680.  
  3681.       max_has_virtual = layout_vbasetypes (t, max_has_virtual);
  3682.       vbases = CLASSTYPE_VBASECLASSES (t);
  3683.       CLASSTYPE_N_VBASECLASSES (t) = list_length (vbases);
  3684.  
  3685.       /* The rtti code should do this.  (mrs) */
  3686. #if 0 
  3687.       while (vbases)
  3688.     {
  3689.       /* Update rtti info with offsets for virtual baseclasses.  */
  3690.       if (flag_rtti && ! BINFO_NEW_VTABLE_MARKED (vbases))
  3691.         prepare_fresh_vtable (vbases, t);
  3692.       vbases = TREE_CHAIN (vbases);
  3693.     }
  3694. #endif
  3695.  
  3696.       {
  3697.     /* Now fixup overrides of all functions in vtables from all
  3698.        direct or indirect virtual base classes.  */
  3699.     tree binfos = BINFO_BASETYPES (TYPE_BINFO (t));
  3700.     int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
  3701.  
  3702.     for (i = 0; i < n_baseclasses; i++)
  3703.       {
  3704.         tree base_binfo = TREE_VEC_ELT (binfos, i);
  3705.         tree basetype = BINFO_TYPE (base_binfo);
  3706.         tree vbases;
  3707.  
  3708.         vbases = CLASSTYPE_VBASECLASSES (basetype);
  3709.         while (vbases)
  3710.           {
  3711.         merge_overrides (binfo_member (BINFO_TYPE (vbases),
  3712.                            CLASSTYPE_VBASECLASSES (t)),
  3713.                  vbases, 1, t);
  3714.         vbases = TREE_CHAIN (vbases);
  3715.           }
  3716.       }
  3717.     }
  3718.  
  3719.       /* Now fixup any virtual function entries from virtual bases
  3720.      that have different deltas.  */
  3721.       vbases = CLASSTYPE_VBASECLASSES (t);
  3722.       while (vbases)
  3723.     {
  3724.       /* We might be able to shorten the amount of work we do by
  3725.          only doing this for vtables that come from virtual bases
  3726.          that have differing offsets, but don't want to miss any
  3727.          entries.  */
  3728.       fixup_vtable_deltas (vbases, 1, t);
  3729.       vbases = TREE_CHAIN (vbases);
  3730.     }
  3731.     }
  3732.  
  3733.   /* Set up the DECL_FIELD_BITPOS of the vfield if we need to, as we
  3734.      might need to know it for setting up the offsets in the vtable
  3735.      (or in thunks) below.  */
  3736.   if (vfield != NULL_TREE
  3737.       && DECL_FIELD_CONTEXT (vfield) != t)
  3738.     {
  3739.       tree binfo = get_binfo (DECL_FIELD_CONTEXT (vfield), t, 0);
  3740.       tree offset = BINFO_OFFSET (binfo);
  3741.  
  3742.       vfield = copy_node (vfield);
  3743.       copy_lang_decl (vfield);
  3744.  
  3745.       if (! integer_zerop (offset))
  3746.     offset = size_binop (MULT_EXPR, offset, size_int (BITS_PER_UNIT));
  3747.       DECL_FIELD_CONTEXT (vfield) = t;
  3748.       DECL_CLASS_CONTEXT (vfield) = t;
  3749.       DECL_FIELD_BITPOS (vfield)
  3750.     = size_binop (PLUS_EXPR, offset, DECL_FIELD_BITPOS (vfield));
  3751.       CLASSTYPE_VFIELD (t) = vfield;
  3752.     }
  3753.     
  3754. #ifdef NOTQUITE
  3755.   cp_warning ("Doing hard virtuals for %T...", t);
  3756. #endif
  3757.  
  3758.   if (has_virtual > max_has_virtual)
  3759.     max_has_virtual = has_virtual;
  3760.   if (max_has_virtual > 0)
  3761.     TYPE_VIRTUAL_P (t) = 1;
  3762.  
  3763.   if (flag_rtti && TYPE_VIRTUAL_P (t) && !pending_hard_virtuals)
  3764.     modify_all_vtables (t, NULL_TREE, NULL_TREE);
  3765.  
  3766.   while (pending_hard_virtuals)
  3767.     {
  3768.       modify_all_vtables (t,
  3769.               TREE_PURPOSE (pending_hard_virtuals),
  3770.               TREE_VALUE (pending_hard_virtuals));
  3771.       pending_hard_virtuals = TREE_CHAIN (pending_hard_virtuals);
  3772.     }
  3773.   doing_hard_virtuals = 0;
  3774.  
  3775.   /* Under our model of GC, every C++ class gets its own virtual
  3776.      function table, at least virtually.  */
  3777.   if (pending_virtuals || (flag_rtti && TYPE_VIRTUAL_P (t)))
  3778.     {
  3779.       pending_virtuals = nreverse (pending_virtuals);
  3780.       /* We must enter these virtuals into the table.  */
  3781.       if (first_vfn_base_index < 0)
  3782.     {
  3783.       if (flag_rtti)
  3784.         pending_virtuals = tree_cons (NULL_TREE,
  3785.         build_vtable_entry (integer_zero_node, build_t_desc (t, 0)),
  3786.             pending_virtuals);
  3787.       else 
  3788.             pending_virtuals = tree_cons (NULL_TREE,
  3789.                 build_vtable_entry (integer_zero_node, integer_zero_node),
  3790.                 pending_virtuals);
  3791.  
  3792. #if 0
  3793.       /* The size is no longer used. */
  3794.       /* now we put the size of the vtable as first entry */
  3795.       pending_virtuals = tree_cons (NULL_TREE, the_null_vtable_entry,
  3796.                     pending_virtuals);
  3797. #endif
  3798.       build_vtable (NULL_TREE, t);
  3799.     }
  3800.       else
  3801.     {
  3802.       /* Here we know enough to change the type of our virtual
  3803.          function table, but we will wait until later this function.  */
  3804.  
  3805.       if (! BINFO_NEW_VTABLE_MARKED (TYPE_BINFO (t)))
  3806.         build_vtable (TREE_VEC_ELT (TYPE_BINFO_BASETYPES (t), first_vfn_base_index), t);
  3807.  
  3808.       /* Update the rtti pointer for this class.  */
  3809.       if (flag_rtti)
  3810.         {
  3811.           tree offset = get_derived_offset (TYPE_BINFO (t), NULL_TREE);
  3812.           offset = size_binop (MINUS_EXPR, integer_zero_node, offset);
  3813.           TREE_VALUE (TYPE_BINFO_VIRTUALS (t))
  3814.         = build_vtable_entry (offset, build_t_desc (t, 0));
  3815.         }
  3816.     }
  3817.  
  3818.       /* If this type has basetypes with constructors, then those
  3819.      constructors might clobber the virtual function table.  But
  3820.      they don't if the derived class shares the exact vtable of the base
  3821.      class.  */
  3822.  
  3823.       CLASSTYPE_NEEDS_VIRTUAL_REINIT (t) = 1;
  3824.     }
  3825.   else if (first_vfn_base_index >= 0)
  3826.     {
  3827.       tree binfo = TREE_VEC_ELT (TYPE_BINFO_BASETYPES (t), first_vfn_base_index);
  3828.       /* This class contributes nothing new to the virtual function
  3829.      table.  However, it may have declared functions which
  3830.      went into the virtual function table "inherited" from the
  3831.      base class.  If so, we grab a copy of those updated functions,
  3832.      and pretend they are ours.  */
  3833.  
  3834.       /* See if we should steal the virtual info from base class.  */
  3835.       if (TYPE_BINFO_VTABLE (t) == NULL_TREE)
  3836.     TYPE_BINFO_VTABLE (t) = BINFO_VTABLE (binfo);
  3837.       if (TYPE_BINFO_VIRTUALS (t) == NULL_TREE)
  3838.     TYPE_BINFO_VIRTUALS (t) = BINFO_VIRTUALS (binfo);
  3839.       if (TYPE_BINFO_VTABLE (t) != BINFO_VTABLE (binfo))
  3840.     CLASSTYPE_NEEDS_VIRTUAL_REINIT (t) = 1;
  3841.     }
  3842.  
  3843.   if (max_has_virtual || first_vfn_base_index >= 0)
  3844.     {
  3845.       CLASSTYPE_VSIZE (t) = has_virtual;
  3846.       if (first_vfn_base_index >= 0)
  3847.     {
  3848.       if (pending_virtuals)
  3849.         TYPE_BINFO_VIRTUALS (t) = chainon (TYPE_BINFO_VIRTUALS (t),
  3850.                         pending_virtuals);
  3851.     }
  3852.       else if (has_virtual)
  3853.     {
  3854.       TYPE_BINFO_VIRTUALS (t) = pending_virtuals;
  3855.       if (write_virtuals >= 0)
  3856.         DECL_VIRTUAL_P (TYPE_BINFO_VTABLE (t)) = 1;
  3857.     }
  3858.     }
  3859.  
  3860.   /* Now lay out the virtual function table.  */
  3861.   if (has_virtual)
  3862.     {
  3863.       tree atype, itype;
  3864.  
  3865.       if (TREE_TYPE (vfield) == ptr_type_node)
  3866.     {
  3867.       /* We must create a pointer to this table because
  3868.          the one inherited from base class does not exist.
  3869.          We will fill in the type when we know what it
  3870.          should really be.  Use `size_int' so values are memoized
  3871.          in common cases.  */
  3872.       itype = build_index_type (size_int (has_virtual));
  3873.       atype = build_array_type (vtable_entry_type, itype);
  3874.       layout_type (atype);
  3875.       TREE_TYPE (vfield) = build_pointer_type (atype);
  3876.     }
  3877.       else
  3878.     {
  3879.       atype = TREE_TYPE (TREE_TYPE (vfield));
  3880.  
  3881.       if (has_virtual != TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (atype))))
  3882.         {
  3883.           /* We must extend (or create) the boundaries on this array,
  3884.          because we picked up virtual functions from multiple
  3885.          base classes.  */
  3886.           itype = build_index_type (size_int (has_virtual));
  3887.           atype = build_array_type (vtable_entry_type, itype);
  3888.           layout_type (atype);
  3889.           vfield = copy_node (vfield);
  3890.           TREE_TYPE (vfield) = build_pointer_type (atype);
  3891.         }
  3892.     }
  3893.  
  3894.       CLASSTYPE_VFIELD (t) = vfield;
  3895.       if (TREE_TYPE (TYPE_BINFO_VTABLE (t)) != atype)
  3896.     {
  3897.       TREE_TYPE (TYPE_BINFO_VTABLE (t)) = atype;
  3898.       DECL_SIZE (TYPE_BINFO_VTABLE (t)) = 0;
  3899.       layout_decl (TYPE_BINFO_VTABLE (t), 0);
  3900.       /* At one time the vtable info was grabbed 2 words at a time.  This
  3901.          fails on sparc unless you have 8-byte alignment.  (tiemann) */
  3902.       DECL_ALIGN (TYPE_BINFO_VTABLE (t))
  3903.         = MAX (TYPE_ALIGN (double_type_node),
  3904.            DECL_ALIGN (TYPE_BINFO_VTABLE (t)));
  3905.     }
  3906.     }
  3907.   else if (first_vfn_base_index >= 0)
  3908.     CLASSTYPE_VFIELD (t) = vfield;
  3909.   CLASSTYPE_VFIELDS (t) = vfields;
  3910.  
  3911.   finish_struct_bits (t, max_has_virtual);
  3912.  
  3913.   /* Promote each bit-field's type to int if it is narrower than that.
  3914.      There's more: complete the rtl for any static member objects which
  3915.      is of the same type we're working on.  */
  3916.   for (x = fields; x; x = TREE_CHAIN (x))
  3917.     {
  3918.       if (DECL_BIT_FIELD (x)
  3919.       && (C_PROMOTING_INTEGER_TYPE_P (TREE_TYPE (x))
  3920.           || DECL_FIELD_SIZE (x) < TYPE_PRECISION (integer_type_node)))
  3921.     {
  3922.       tree type = TREE_TYPE (x);
  3923.  
  3924.       /* Preserve unsignedness if traditional or if not really getting
  3925.          any wider.  */
  3926.       if (TREE_UNSIGNED (type)
  3927.           && (flag_traditional
  3928.           ||
  3929.           (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)
  3930.            && DECL_FIELD_SIZE (x) == TYPE_PRECISION (integer_type_node))))
  3931.         TREE_TYPE (x) = unsigned_type_node;
  3932.       else
  3933.         TREE_TYPE (x) = integer_type_node;
  3934.     }
  3935.  
  3936.       if (TREE_CODE (x) == VAR_DECL && TREE_STATIC (x)
  3937.       && TREE_TYPE (x) == t)
  3938.     {
  3939.       DECL_MODE (x) = TYPE_MODE (t);
  3940.       make_decl_rtl (x, NULL, 0);
  3941.     }
  3942.     }
  3943.  
  3944.   /* Now add the tags, if any, to the list of TYPE_DECLs
  3945.      defined for this type.  */
  3946.   if (CLASSTYPE_TAGS (t))
  3947.     {
  3948.       x = CLASSTYPE_TAGS (t);
  3949.       last_x = tree_last (TYPE_FIELDS (t));
  3950.       while (x)
  3951.     {
  3952.       tree tag = TYPE_NAME (TREE_VALUE (x));
  3953.  
  3954.       /* Check to see if it is already there.  This will be the case if
  3955.          was do enum { red; } color; */
  3956.       if (chain_member (tag, TYPE_FIELDS (t)))
  3957.           {
  3958.         x = TREE_CHAIN (x);
  3959.         continue;
  3960.           }
  3961.  
  3962. #ifdef DWARF_DEBUGGING_INFO
  3963.       if (write_symbols == DWARF_DEBUG)
  3964.         {
  3965.           /* Notify dwarfout.c that this TYPE_DECL node represent a
  3966.          gratuitous typedef.  */
  3967.           DECL_IGNORED_P (tag) = 1;
  3968.         }
  3969. #endif /* DWARF_DEBUGGING_INFO */
  3970.  
  3971.       TREE_NONLOCAL_FLAG (TREE_VALUE (x)) = 0;
  3972.       x = TREE_CHAIN (x);
  3973.       last_x = chainon (last_x, tag);
  3974.     }
  3975.       if (TYPE_FIELDS (t) == NULL_TREE)
  3976.     TYPE_FIELDS (t) = last_x;
  3977.       CLASSTYPE_LOCAL_TYPEDECLS (t) = 1;
  3978.     }
  3979.  
  3980.   if (TYPE_HAS_CONSTRUCTOR (t))
  3981.     {
  3982.       tree vfields = CLASSTYPE_VFIELDS (t);
  3983.  
  3984.       while (vfields)
  3985.     {
  3986.       /* Mark the fact that constructor for T
  3987.          could affect anybody inheriting from T
  3988.          who wants to initialize vtables for VFIELDS's type.  */
  3989.       if (VF_DERIVED_VALUE (vfields))
  3990.         TREE_ADDRESSABLE (vfields) = 1;
  3991.       vfields = TREE_CHAIN (vfields);
  3992.     }
  3993.       if (any_default_members != 0)
  3994.     build_class_init_list (t);
  3995.     }
  3996.   else if (TYPE_NEEDS_CONSTRUCTING (t))
  3997.     build_class_init_list (t);
  3998.  
  3999.   if (! IS_SIGNATURE (t))
  4000.     embrace_waiting_friends (t);
  4001.  
  4002.   /* Write out inline function definitions.  */
  4003.   do_inline_function_hair (t, CLASSTYPE_INLINE_FRIENDS (t));
  4004.   CLASSTYPE_INLINE_FRIENDS (t) = 0;
  4005.  
  4006.   if (CLASSTYPE_VSIZE (t) != 0)
  4007.     {
  4008. #if 0
  4009.       /* This is now done above. */
  4010.       if (DECL_FIELD_CONTEXT (vfield) != t)
  4011.     {
  4012.       tree binfo = get_binfo (DECL_FIELD_CONTEXT (vfield), t, 0);
  4013.       tree offset = BINFO_OFFSET (binfo);
  4014.  
  4015.       vfield = copy_node (vfield);
  4016.       copy_lang_decl (vfield);
  4017.  
  4018.       if (! integer_zerop (offset))
  4019.         offset = size_binop (MULT_EXPR, offset, size_int (BITS_PER_UNIT));
  4020.       DECL_FIELD_CONTEXT (vfield) = t;
  4021.       DECL_CLASS_CONTEXT (vfield) = t;
  4022.       DECL_FIELD_BITPOS (vfield)
  4023.         = size_binop (PLUS_EXPR, offset, DECL_FIELD_BITPOS (vfield));
  4024.       CLASSTYPE_VFIELD (t) = vfield;
  4025.     }
  4026. #endif
  4027.  
  4028.       /* In addition to this one, all the other vfields should be listed. */
  4029.       /* Before that can be done, we have to have FIELD_DECLs for them, and
  4030.      a place to find them.  */
  4031.       TYPE_NONCOPIED_PARTS (t) = build_tree_list (default_conversion (TYPE_BINFO_VTABLE (t)), vfield);
  4032.  
  4033.       if (warn_nonvdtor && TYPE_HAS_DESTRUCTOR (t)
  4034.       && DECL_VINDEX (TREE_VEC_ELT (method_vec, 0)) == NULL_TREE)
  4035.     cp_warning ("`%#T' has virtual functions but non-virtual destructor",
  4036.             t);
  4037.     }
  4038.  
  4039.   /* Make the rtl for any new vtables we have created, and unmark
  4040.      the base types we marked.  */
  4041.   finish_vtbls (TYPE_BINFO (t), 1, t);
  4042.   TYPE_BEING_DEFINED (t) = 0;
  4043.   hack_incomplete_structures (t);
  4044.  
  4045. #if 0
  4046.   if (TYPE_NAME (t) && TYPE_IDENTIFIER (t))
  4047.     undo_template_name_overload (TYPE_IDENTIFIER (t), 1);
  4048. #endif
  4049.   if (current_class_type)
  4050.     popclass (0);
  4051.   else
  4052.     error ("trying to finish struct, but kicked out due to previous parse errors.");
  4053.  
  4054.   resume_momentary (old);
  4055.  
  4056.   if (flag_cadillac)
  4057.     cadillac_finish_struct (t);
  4058.  
  4059. #if 0
  4060.   /* This has to be done after we have sorted out what to do with
  4061.      the enclosing type.  */
  4062.   if (write_symbols != DWARF_DEBUG)
  4063.     {
  4064.       /* Be smarter about nested classes here.  If a type is nested,
  4065.      only output it if we would output the enclosing type.  */
  4066.       if (DECL_CONTEXT (TYPE_NAME (t))
  4067.       && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (TYPE_NAME (t)))) == 't')
  4068.     DECL_IGNORED_P (TYPE_NAME (t)) = TREE_ASM_WRITTEN (TYPE_NAME (t));
  4069.     }
  4070. #endif
  4071.  
  4072.   if (write_symbols != DWARF_DEBUG)
  4073.     {
  4074.       /* If the type has methods, we want to think about cutting down
  4075.      the amount of symbol table stuff we output.  The value stored in
  4076.      the TYPE_DECL's DECL_IGNORED_P slot is a first approximation.
  4077.      For example, if a member function is seen and we decide to
  4078.      write out that member function, then we can change the value
  4079.      of the DECL_IGNORED_P slot, and the type will be output when
  4080.      that member function's debug info is written out.  */
  4081.       if (CLASSTYPE_METHOD_VEC (t))
  4082.     {
  4083.       extern tree pending_vtables;
  4084.  
  4085.       /* Don't output full info about any type
  4086.          which does not have its implementation defined here.  */
  4087.       if (TYPE_VIRTUAL_P (t) && write_virtuals == 2)
  4088.         TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t))
  4089.           = (value_member (TYPE_IDENTIFIER (t), pending_vtables) == 0);
  4090.       else if (CLASSTYPE_INTERFACE_ONLY (t))
  4091.         TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t)) = 1;
  4092.       else if (CLASSTYPE_INTERFACE_UNKNOWN (t))
  4093.         /* Only a first approximation!  */
  4094.         TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t)) = 1;
  4095.     }
  4096.       else if (CLASSTYPE_INTERFACE_ONLY (t))
  4097.     TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t)) = 1;
  4098.     }
  4099.  
  4100.   /* Finish debugging output for this type.  */
  4101.   rest_of_type_compilation (t, toplevel_bindings_p ());
  4102.  
  4103.   return t;
  4104. }
  4105.  
  4106. /* Return non-zero if the effective type of INSTANCE is static.
  4107.    Used to determine whether the virtual function table is needed
  4108.    or not.
  4109.  
  4110.    *NONNULL is set iff INSTANCE can be known to be nonnull, regardless
  4111.    of our knowledge of its type.  */
  4112. int
  4113. resolves_to_fixed_type_p (instance, nonnull)
  4114.      tree instance;
  4115.      int *nonnull;
  4116. {
  4117.   switch (TREE_CODE (instance))
  4118.     {
  4119.     case INDIRECT_REF:
  4120.       /* Check that we are not going through a cast of some sort.  */
  4121.       if (TREE_TYPE (instance)
  4122.       == TREE_TYPE (TREE_TYPE (TREE_OPERAND (instance, 0))))
  4123.     instance = TREE_OPERAND (instance, 0);
  4124.       /* fall through...  */
  4125.     case CALL_EXPR:
  4126.       /* This is a call to a constructor, hence it's never zero.  */
  4127.       if (TREE_HAS_CONSTRUCTOR (instance))
  4128.     {
  4129.       if (nonnull)
  4130.         *nonnull = 1;
  4131.       return 1;
  4132.     }
  4133.       return 0;
  4134.  
  4135.     case SAVE_EXPR:
  4136.       /* This is a call to a constructor, hence it's never zero.  */
  4137.       if (TREE_HAS_CONSTRUCTOR (instance))
  4138.     {
  4139.       if (nonnull)
  4140.         *nonnull = 1;
  4141.       return 1;
  4142.     }
  4143.       return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull);
  4144.  
  4145.     case RTL_EXPR:
  4146.       /* This is a call to `new', hence it's never zero.  */
  4147.       if (TREE_CALLS_NEW (instance))
  4148.     {
  4149.       if (nonnull)
  4150.         *nonnull = 1;
  4151.       return 1;
  4152.     }
  4153.       return 0;
  4154.  
  4155.     case PLUS_EXPR:
  4156.     case MINUS_EXPR:
  4157.       if (TREE_CODE (TREE_OPERAND (instance, 1)) == INTEGER_CST)
  4158.     /* Propagate nonnull.  */
  4159.     resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull);
  4160.       if (TREE_CODE (TREE_OPERAND (instance, 0)) == ADDR_EXPR)
  4161.     return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull);
  4162.       return 0;
  4163.  
  4164.     case NOP_EXPR:
  4165.     case CONVERT_EXPR:
  4166.       return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull);
  4167.  
  4168.     case ADDR_EXPR:
  4169.       if (nonnull)
  4170.     *nonnull = 1;
  4171.       return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull);
  4172.  
  4173.     case COMPONENT_REF:
  4174.       return resolves_to_fixed_type_p (TREE_OPERAND (instance, 1), nonnull);
  4175.  
  4176.     case WITH_CLEANUP_EXPR:
  4177.       if (TREE_CODE (TREE_OPERAND (instance, 0)) == ADDR_EXPR)
  4178.     return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull);
  4179.       /* fall through... */
  4180.     case VAR_DECL:
  4181.     case FIELD_DECL:
  4182.       if (TREE_CODE (TREE_TYPE (instance)) == ARRAY_TYPE
  4183.       && IS_AGGR_TYPE (TREE_TYPE (TREE_TYPE (instance))))
  4184.     {
  4185.       if (nonnull)
  4186.         *nonnull = 1;
  4187.       return 1;
  4188.     }
  4189.       /* fall through... */
  4190.     case TARGET_EXPR:
  4191.     case PARM_DECL:
  4192.       if (IS_AGGR_TYPE (TREE_TYPE (instance)))
  4193.     {
  4194.       if (nonnull)
  4195.         *nonnull = 1;
  4196.       return 1;
  4197.     }
  4198.       else if (nonnull)
  4199.     {
  4200.       if (instance == current_class_decl
  4201.           && flag_this_is_variable <= 0)
  4202.         {
  4203.           /* Some people still use `this = 0' inside destructors.  */
  4204.           *nonnull = ! DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (current_function_decl));
  4205.           /* In a constructor, we know our type.  */
  4206.           if (flag_this_is_variable < 0)
  4207.         return 1;
  4208.         }
  4209.       else if (TREE_CODE (TREE_TYPE (instance)) == REFERENCE_TYPE)
  4210.         /* Reference variables should be references to objects.  */
  4211.         *nonnull = 1;
  4212.     }
  4213.       return 0;
  4214.  
  4215.     default:
  4216.       return 0;
  4217.     }
  4218. }
  4219.  
  4220. void
  4221. init_class_processing ()
  4222. {
  4223.   current_class_depth = 0;
  4224.   current_class_stacksize = 10;
  4225.   current_class_base = (tree *)xmalloc(current_class_stacksize * sizeof (tree));
  4226.   current_class_stack = current_class_base;
  4227.  
  4228.   current_lang_stacksize = 10;
  4229.   current_lang_base = (tree *)xmalloc(current_lang_stacksize * sizeof (tree));
  4230.   current_lang_stack = current_lang_base;
  4231.  
  4232.   /* Keep these values lying around.  */
  4233.   the_null_vtable_entry = build_vtable_entry (integer_zero_node, integer_zero_node);
  4234.   base_layout_decl = build_lang_field_decl (FIELD_DECL, NULL_TREE, error_mark_node);
  4235.   TREE_TYPE (base_layout_decl) = make_node (RECORD_TYPE);
  4236.  
  4237.   gcc_obstack_init (&class_obstack);
  4238. }
  4239.  
  4240. /* Set current scope to NAME. CODE tells us if this is a
  4241.    STRUCT, UNION, or ENUM environment.
  4242.  
  4243.    NAME may end up being NULL_TREE if this is an anonymous or
  4244.    late-bound struct (as in "struct { ... } foo;")  */
  4245.  
  4246. /* Set global variables CURRENT_CLASS_NAME and CURRENT_CLASS_TYPE to
  4247.    appropriate values, found by looking up the type definition of
  4248.    NAME (as a CODE).
  4249.  
  4250.    If MODIFY is 1, we set IDENTIFIER_CLASS_VALUE's of names
  4251.    which can be seen locally to the class.  They are shadowed by
  4252.    any subsequent local declaration (including parameter names).
  4253.  
  4254.    If MODIFY is 2, we set IDENTIFIER_CLASS_VALUE's of names
  4255.    which have static meaning (i.e., static members, static
  4256.    member functions, enum declarations, etc).
  4257.  
  4258.    If MODIFY is 3, we set IDENTIFIER_CLASS_VALUE of names
  4259.    which can be seen locally to the class (as in 1), but
  4260.    know that we are doing this for declaration purposes
  4261.    (i.e. friend foo::bar (int)).
  4262.  
  4263.    So that we may avoid calls to lookup_name, we cache the _TYPE
  4264.    nodes of local TYPE_DECLs in the TREE_TYPE field of the name.
  4265.  
  4266.    For multiple inheritance, we perform a two-pass depth-first search
  4267.    of the type lattice.  The first pass performs a pre-order search,
  4268.    marking types after the type has had its fields installed in
  4269.    the appropriate IDENTIFIER_CLASS_VALUE slot.  The second pass merely
  4270.    unmarks the marked types.  If a field or member function name
  4271.    appears in an ambiguous way, the IDENTIFIER_CLASS_VALUE of
  4272.    that name becomes `error_mark_node'.  */
  4273.  
  4274. void
  4275. pushclass (type, modify)
  4276.      tree type;
  4277.      int modify;
  4278. {
  4279.   push_memoized_context (type, modify);
  4280.  
  4281.   current_class_depth++;
  4282.   *current_class_stack++ = current_class_name;
  4283.   *current_class_stack++ = current_class_type;
  4284.   if (current_class_stack >= current_class_base + current_class_stacksize)
  4285.     {
  4286.       current_class_base =
  4287.     (tree *)xrealloc (current_class_base,
  4288.               sizeof (tree) * (current_class_stacksize + 10));
  4289.       current_class_stack = current_class_base + current_class_stacksize;
  4290.       current_class_stacksize += 10;
  4291.     }
  4292.  
  4293.   current_class_name = TYPE_NAME (type);
  4294.   if (TREE_CODE (current_class_name) == TYPE_DECL)
  4295.     current_class_name = DECL_NAME (current_class_name);
  4296.   current_class_type = type;
  4297.  
  4298.   if (previous_class_type != NULL_TREE
  4299.       && (type != previous_class_type || TYPE_SIZE (previous_class_type) == NULL_TREE)
  4300.       && current_class_depth == 1)
  4301.     {
  4302.       /* Forcibly remove any old class remnants.  */
  4303.       popclass (-1);
  4304.       previous_class_type = NULL_TREE;
  4305.     }
  4306.  
  4307.   pushlevel_class ();
  4308.  
  4309.   if (modify)
  4310.     {
  4311.       tree tags;
  4312.       tree this_fndecl = current_function_decl;
  4313.  
  4314.       if (current_function_decl
  4315.       && DECL_CONTEXT (current_function_decl)
  4316.       && TREE_CODE (DECL_CONTEXT (current_function_decl)) == FUNCTION_DECL)
  4317.     current_function_decl = DECL_CONTEXT (current_function_decl);
  4318.       else
  4319.     current_function_decl = NULL_TREE;
  4320.  
  4321.       if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE)
  4322.     declare_uninstantiated_type_level ();
  4323.       else if (type != previous_class_type || current_class_depth > 1)
  4324.     {
  4325.       build_mi_matrix (type);
  4326.       push_class_decls (type);
  4327.       free_mi_matrix ();
  4328.       if (current_class_depth == 1)
  4329.         previous_class_type = type;
  4330.     }
  4331.       else
  4332.     {
  4333.       tree item;
  4334.  
  4335.       /* Hooray, we successfully cached; let's just install the
  4336.          cached class_shadowed list, and walk through it to get the
  4337.          IDENTIFIER_TYPE_VALUEs correct.  */
  4338.       set_class_shadows (previous_class_values);
  4339.       for (item = previous_class_values; item; item = TREE_CHAIN (item))
  4340.         {
  4341.           tree id = TREE_PURPOSE (item);
  4342.           tree decl = IDENTIFIER_CLASS_VALUE (id);
  4343.  
  4344.           if (TREE_CODE (decl) == TYPE_DECL)
  4345.         set_identifier_type_value (id, TREE_TYPE (decl));
  4346.         }
  4347.       unuse_fields (type);
  4348.     }
  4349.  
  4350.       if (IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (type)))
  4351.     overload_template_name (current_class_name, 0);
  4352.  
  4353.       for (tags = CLASSTYPE_TAGS (type); tags; tags = TREE_CHAIN (tags))
  4354.     {
  4355.       TREE_NONLOCAL_FLAG (TREE_VALUE (tags)) = 1;
  4356.       if (! TREE_PURPOSE (tags))
  4357.         continue;
  4358.       pushtag (TREE_PURPOSE (tags), TREE_VALUE (tags), 0);
  4359.     }
  4360.  
  4361.       current_function_decl = this_fndecl;
  4362.     }
  4363.  
  4364.   if (flag_cadillac)
  4365.     cadillac_push_class (type);
  4366. }
  4367.  
  4368. /* Get out of the current class scope. If we were in a class scope
  4369.    previously, that is the one popped to.  The flag MODIFY tells whether
  4370.    the current scope declarations needs to be modified as a result of
  4371.    popping to the previous scope.  0 is used for class definitions.  */
  4372. void
  4373. popclass (modify)
  4374.      int modify;
  4375. {
  4376.   if (flag_cadillac)
  4377.     cadillac_pop_class ();
  4378.  
  4379.   if (modify < 0)
  4380.     {
  4381.       /* Back this old class out completely.  */
  4382.       tree tags = CLASSTYPE_TAGS (previous_class_type);
  4383.       tree t;
  4384.  
  4385.       /* This code can be seen as a cache miss.  When we've cached a
  4386.      class' scope's bindings and we can't use them, we need to reset
  4387.      them.  This is it!  */
  4388.       for (t = previous_class_values; t; t = TREE_CHAIN (t))
  4389.     IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (t)) = NULL_TREE;
  4390.       while (tags)
  4391.     {
  4392.       TREE_NONLOCAL_FLAG (TREE_VALUE (tags)) = 0;
  4393.       tags = TREE_CHAIN (tags);
  4394.     }
  4395.       goto ret;
  4396.     }
  4397.  
  4398.   if (modify)
  4399.     {
  4400.       /* Just remove from this class what didn't make
  4401.      it into IDENTIFIER_CLASS_VALUE.  */
  4402.       tree tags = CLASSTYPE_TAGS (current_class_type);
  4403.  
  4404.       while (tags)
  4405.     {
  4406.       TREE_NONLOCAL_FLAG (TREE_VALUE (tags)) = 0;
  4407.       tags = TREE_CHAIN (tags);
  4408.     }
  4409.       if (IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (current_class_type)))
  4410.     undo_template_name_overload (current_class_name, 0);
  4411.     }
  4412.  
  4413.   /* Force clearing of IDENTIFIER_CLASS_VALUEs after a class definition,
  4414.      since not all class decls make it there currently.  */
  4415.   poplevel_class (! modify);
  4416.  
  4417.   /* Since poplevel_class does the popping of class decls nowadays,
  4418.      this really only frees the obstack used for these decls.
  4419.      That's why it had to be moved down here.  */
  4420.   if (modify)
  4421.     pop_class_decls (current_class_type);
  4422.  
  4423.   current_class_depth--;
  4424.   current_class_type = *--current_class_stack;
  4425.   current_class_name = *--current_class_stack;
  4426.  
  4427.   pop_memoized_context (modify);
  4428.  
  4429.  ret:
  4430.   ;
  4431. }
  4432.  
  4433. /* When entering a class scope, all enclosing class scopes' names with
  4434.    static meaning (static variables, static functions, types and enumerators)
  4435.    have to be visible.  This recursive function calls pushclass for all
  4436.    enclosing class contexts until global or a local scope is reached.
  4437.    TYPE is the enclosed class and MODIFY is equivalent with the pushclass
  4438.    formal of the same name.  */
  4439.  
  4440. void
  4441. push_nested_class (type, modify)
  4442.      tree type;
  4443.      int modify;
  4444. {
  4445.   tree context;
  4446.  
  4447.   if (type == error_mark_node || ! IS_AGGR_TYPE (type))
  4448.     return;
  4449.   
  4450.   context = DECL_CONTEXT (TYPE_NAME (type));
  4451.  
  4452.   if (context && TREE_CODE (context) == RECORD_TYPE)
  4453.     push_nested_class (context, 2);
  4454.   pushclass (type, modify);
  4455. }
  4456.  
  4457. /* Undoes a push_nested_class call.  MODIFY is passed on to popclass.  */
  4458.  
  4459. void
  4460. pop_nested_class (modify)
  4461.      int modify;
  4462. {
  4463.   tree context = DECL_CONTEXT (TYPE_NAME (current_class_type));
  4464.  
  4465.   popclass (modify);
  4466.   if (context && TREE_CODE (context) == RECORD_TYPE)
  4467.     pop_nested_class (modify);
  4468. }
  4469.  
  4470. /* Set global variables CURRENT_LANG_NAME to appropriate value
  4471.    so that behavior of name-mangling machinery is correct.  */
  4472.  
  4473. void
  4474. push_lang_context (name)
  4475.      tree name;
  4476. {
  4477.   *current_lang_stack++ = current_lang_name;
  4478.   if (current_lang_stack >= current_lang_base + current_lang_stacksize)
  4479.     {
  4480.       current_lang_base =
  4481.     (tree *)xrealloc (current_lang_base,
  4482.               sizeof (tree) * (current_lang_stacksize + 10));
  4483.       current_lang_stack = current_lang_base + current_lang_stacksize;
  4484.       current_lang_stacksize += 10;
  4485.     }
  4486.  
  4487.   if (name == lang_name_cplusplus)
  4488.     {
  4489.       strict_prototype = strict_prototypes_lang_cplusplus;
  4490.       current_lang_name = name;
  4491.     }
  4492.   else if (name == lang_name_c)
  4493.     {
  4494.       strict_prototype = strict_prototypes_lang_c;
  4495.       current_lang_name = name;
  4496.     }
  4497.   else
  4498.     error ("language string `\"%s\"' not recognized", IDENTIFIER_POINTER (name));
  4499.  
  4500.   if (flag_cadillac)
  4501.     cadillac_push_lang (name);
  4502. }
  4503.   
  4504. /* Get out of the current language scope.  */
  4505. void
  4506. pop_lang_context ()
  4507. {
  4508.   if (flag_cadillac)
  4509.     cadillac_pop_lang ();
  4510.  
  4511.   current_lang_name = *--current_lang_stack;
  4512.   if (current_lang_name == lang_name_cplusplus)
  4513.     strict_prototype = strict_prototypes_lang_cplusplus;
  4514.   else if (current_lang_name == lang_name_c)
  4515.     strict_prototype = strict_prototypes_lang_c;
  4516. }
  4517.  
  4518. int
  4519. root_lang_context_p ()
  4520. {
  4521.   return current_lang_stack == current_lang_base;
  4522. }
  4523.  
  4524. /* Type instantiation routines.  */
  4525.  
  4526. /* This function will instantiate the type of the expression given
  4527.    in RHS to match the type of LHSTYPE.  If LHSTYPE is NULL_TREE,
  4528.    or other errors exist, the TREE_TYPE of RHS will be ERROR_MARK_NODE.
  4529.  
  4530.    This function is used in build_modify_expr, convert_arguments,
  4531.    build_c_cast, and compute_conversion_costs.  */
  4532. tree
  4533. instantiate_type (lhstype, rhs, complain)
  4534.      tree lhstype, rhs;
  4535.      int complain;
  4536. {
  4537.   if (TREE_CODE (lhstype) == UNKNOWN_TYPE)
  4538.     {
  4539.       if (complain)
  4540.     error ("not enough type information");
  4541.       return error_mark_node;
  4542.     }
  4543.  
  4544.   if (TREE_TYPE (rhs) != NULL_TREE && ! (type_unknown_p (rhs)))
  4545.     return rhs;
  4546.  
  4547.   /* This should really only be used when attempting to distinguish
  4548.      what sort of a pointer to function we have.  For now, any
  4549.      arithmetic operation which is not supported on pointers
  4550.      is rejected as an error.  */
  4551.  
  4552.   switch (TREE_CODE (rhs))
  4553.     {
  4554.     case TYPE_EXPR:
  4555.     case CONVERT_EXPR:
  4556.     case SAVE_EXPR:
  4557.     case CONSTRUCTOR:
  4558.     case BUFFER_REF:
  4559.       my_friendly_abort (177);
  4560.       return error_mark_node;
  4561.  
  4562.     case INDIRECT_REF:
  4563.     case ARRAY_REF:
  4564.       TREE_TYPE (rhs) = lhstype;
  4565.       lhstype = build_pointer_type (lhstype);
  4566.       TREE_OPERAND (rhs, 0)
  4567.     = instantiate_type (lhstype, TREE_OPERAND (rhs, 0), complain);
  4568.       if (TREE_OPERAND (rhs, 0) == error_mark_node)
  4569.     return error_mark_node;
  4570.  
  4571.       return rhs;
  4572.  
  4573.     case NOP_EXPR:
  4574.       rhs = copy_node (TREE_OPERAND (rhs, 0));
  4575.       TREE_TYPE (rhs) = unknown_type_node;
  4576.       return instantiate_type (lhstype, rhs, complain);
  4577.  
  4578.     case COMPONENT_REF:
  4579.       {
  4580.     tree field = TREE_OPERAND (rhs, 1);
  4581.     if (TREE_CODE (field) == TREE_LIST)
  4582.       {
  4583.         tree function = instantiate_type (lhstype, field, complain);
  4584.         if (function == error_mark_node)
  4585.           return error_mark_node;
  4586.         my_friendly_assert (TREE_CODE (function) == FUNCTION_DECL, 185);
  4587.         if (DECL_VINDEX (function))
  4588.           {
  4589.         tree base = TREE_OPERAND (rhs, 0);
  4590.         tree base_ptr = build_unary_op (ADDR_EXPR, base, 0);
  4591.         if (base_ptr == error_mark_node)
  4592.           return error_mark_node;
  4593.         base_ptr = convert_pointer_to (DECL_CONTEXT (function), base_ptr);
  4594.         if (base_ptr == error_mark_node)
  4595.           return error_mark_node;
  4596.         return build_vfn_ref (&base_ptr, base, DECL_VINDEX (function));
  4597.           }
  4598.         return function;
  4599.       }
  4600.  
  4601.     my_friendly_assert (TREE_CODE (field) == FIELD_DECL, 178);
  4602.     my_friendly_assert (!(TREE_CODE (TREE_TYPE (field)) == FUNCTION_TYPE
  4603.                   || TREE_CODE (TREE_TYPE (field)) == METHOD_TYPE),
  4604.                 179);
  4605.  
  4606.     TREE_TYPE (rhs) = lhstype;
  4607.     /* First look for an exact match  */
  4608.  
  4609.     while (field && TREE_TYPE (field) != lhstype)
  4610.       field = DECL_CHAIN (field);
  4611.     if (field)
  4612.       {
  4613.         TREE_OPERAND (rhs, 1) = field;
  4614.         return rhs;
  4615.       }
  4616.  
  4617.     /* No exact match found, look for a compatible function.  */
  4618.     field = TREE_OPERAND (rhs, 1);
  4619.     while (field && ! comptypes (lhstype, TREE_TYPE (field), 0))
  4620.       field = DECL_CHAIN (field);
  4621.     if (field)
  4622.       {
  4623.         TREE_OPERAND (rhs, 1) = field;
  4624.         field = DECL_CHAIN (field);
  4625.         while (field && ! comptypes (lhstype, TREE_TYPE (field), 0))
  4626.           field = DECL_CHAIN (field);
  4627.         if (field)
  4628.           {
  4629.         if (complain)
  4630.           error ("ambiguous overload for COMPONENT_REF requested");
  4631.         return error_mark_node;
  4632.           }
  4633.       }
  4634.     else
  4635.       {
  4636.         if (complain)
  4637.           error ("no appropriate overload exists for COMPONENT_REF");
  4638.         return error_mark_node;
  4639.       }
  4640.     return rhs;
  4641.       }
  4642.  
  4643.     case TREE_LIST:
  4644.       {
  4645.     tree elem, baselink, name;
  4646.     int globals = overloaded_globals_p (rhs);
  4647.  
  4648. #if 0 /* obsolete */
  4649.     /* If there's only one function we know about, return that.  */
  4650.     if (globals > 0 && TREE_CHAIN (rhs) == NULL_TREE)
  4651.       return TREE_VALUE (rhs);
  4652. #endif
  4653.  
  4654.     /* First look for an exact match.  Search either overloaded
  4655.        functions or member functions.  May have to undo what
  4656.        `default_conversion' might do to lhstype.  */
  4657.  
  4658.     if (TYPE_PTRMEMFUNC_P (lhstype))
  4659.       lhstype = TYPE_PTRMEMFUNC_FN_TYPE (lhstype);
  4660.  
  4661.     if (TREE_CODE (lhstype) == POINTER_TYPE)
  4662.       if (TREE_CODE (TREE_TYPE (lhstype)) == FUNCTION_TYPE
  4663.           || TREE_CODE (TREE_TYPE (lhstype)) == METHOD_TYPE)
  4664.         lhstype = TREE_TYPE (lhstype);
  4665.       else
  4666.         {
  4667.           if (complain)
  4668.         error ("invalid type combination for overload");
  4669.           return error_mark_node;
  4670.         }
  4671.  
  4672.     if (TREE_CODE (lhstype) != FUNCTION_TYPE && globals > 0)
  4673.       {
  4674.         if (complain)
  4675.           cp_error ("cannot resolve overloaded function `%D' based on non-function type",
  4676.              TREE_PURPOSE (rhs));
  4677.         return error_mark_node;
  4678.       }
  4679.  
  4680.     if (globals > 0)
  4681.       {
  4682.         elem = get_first_fn (rhs);
  4683.         while (elem)
  4684.           if (! comptypes (lhstype, TREE_TYPE (elem), 1))
  4685.         elem = DECL_CHAIN (elem);
  4686.           else
  4687.         return elem;
  4688.  
  4689.         /* No exact match found, look for a compatible template.  */
  4690.         {
  4691.           tree save_elem = 0;
  4692.           for (elem = get_first_fn (rhs); elem; elem = DECL_CHAIN (elem))
  4693.         if (TREE_CODE (elem) == TEMPLATE_DECL)
  4694.           {
  4695.             int n = TREE_VEC_LENGTH (DECL_TEMPLATE_PARMS (elem));
  4696.             tree *t = (tree *) alloca (sizeof (tree) * n);
  4697.             int i, d = 0;
  4698.             i = type_unification (DECL_TEMPLATE_PARMS (elem), t,
  4699.                       TYPE_ARG_TYPES (TREE_TYPE (elem)),
  4700.                       TYPE_ARG_TYPES (lhstype), &d, 0);
  4701.             if (i == 0)
  4702.               {
  4703.             if (save_elem)
  4704.               {
  4705.                 cp_error ("ambiguous template instantiation converting to `%#T'", lhstype);
  4706.                 return error_mark_node;
  4707.               }
  4708.             save_elem = instantiate_template (elem, t);
  4709.             /* Check the return type.  */
  4710.             if (! comptypes (TREE_TYPE (lhstype),
  4711.                      TREE_TYPE (TREE_TYPE (save_elem)), 1))
  4712.               save_elem = 0;
  4713.               }
  4714.           }
  4715.           if (save_elem)
  4716.         return save_elem;
  4717.         }
  4718.  
  4719.         /* No match found, look for a compatible function.  */
  4720.         elem = get_first_fn (rhs);
  4721.         while (elem && comp_target_types (lhstype,
  4722.                           TREE_TYPE (elem), 1) <= 0)
  4723.           elem = DECL_CHAIN (elem);
  4724.         if (elem)
  4725.           {
  4726.         tree save_elem = elem;
  4727.         elem = DECL_CHAIN (elem);
  4728.         while (elem && comp_target_types (lhstype,
  4729.                           TREE_TYPE (elem), 0) <= 0)
  4730.           elem = DECL_CHAIN (elem);
  4731.         if (elem)
  4732.           {
  4733.             if (complain)
  4734.               {
  4735.             cp_error ("cannot resolve overload to target type `%#T'",
  4736.                   lhstype);
  4737.             cp_error_at ("  ambiguity between `%#D'", save_elem);
  4738.             cp_error_at ("  and `%#D', at least", elem);
  4739.               }
  4740.             return error_mark_node;
  4741.           }
  4742.         return save_elem;
  4743.           }
  4744.         if (complain)
  4745.           {
  4746.         cp_error ("cannot resolve overload to target type `%#T'",
  4747.               lhstype);
  4748.         cp_error ("  because no suitable overload of function `%D' exists",
  4749.               TREE_PURPOSE (rhs));
  4750.           }
  4751.         return error_mark_node;
  4752.       }
  4753.  
  4754.     if (TREE_NONLOCAL_FLAG (rhs))
  4755.       {
  4756.         /* Got to get it as a baselink.  */
  4757.         rhs = lookup_fnfields (TYPE_BINFO (current_class_type),
  4758.                    TREE_PURPOSE (rhs), 0);
  4759.       }
  4760.     else
  4761.       {
  4762.         my_friendly_assert (TREE_CHAIN (rhs) == NULL_TREE, 181);
  4763.         if (TREE_CODE (TREE_VALUE (rhs)) == TREE_LIST)
  4764.           rhs = TREE_VALUE (rhs);
  4765.         my_friendly_assert (TREE_CODE (TREE_VALUE (rhs)) == FUNCTION_DECL,
  4766.                 182);
  4767.       }
  4768.  
  4769.     for (baselink = rhs; baselink;
  4770.          baselink = next_baselink (baselink))
  4771.       {
  4772.         elem = TREE_VALUE (baselink);
  4773.         while (elem)
  4774.           if (comptypes (lhstype, TREE_TYPE (elem), 1))
  4775.         return elem;
  4776.           else
  4777.         elem = DECL_CHAIN (elem);
  4778.       }
  4779.  
  4780.     /* No exact match found, look for a compatible method.  */
  4781.     for (baselink = rhs; baselink;
  4782.          baselink = next_baselink (baselink))
  4783.       {
  4784.         elem = TREE_VALUE (baselink);
  4785.         while (elem && comp_target_types (lhstype,
  4786.                           TREE_TYPE (elem), 1) <= 0)
  4787.           elem = DECL_CHAIN (elem);
  4788.         if (elem)
  4789.           {
  4790.         tree save_elem = elem;
  4791.         elem = DECL_CHAIN (elem);
  4792.         while (elem && comp_target_types (lhstype,
  4793.                           TREE_TYPE (elem), 0) <= 0)
  4794.           elem = DECL_CHAIN (elem);
  4795.         if (elem)
  4796.           {
  4797.             if (complain)
  4798.               error ("ambiguous overload for overloaded method requested");
  4799.             return error_mark_node;
  4800.           }
  4801.         return save_elem;
  4802.           }
  4803.         name = DECL_NAME (TREE_VALUE (rhs));
  4804. #if 0
  4805.         if (TREE_CODE (lhstype) == FUNCTION_TYPE && globals < 0)
  4806.           {
  4807.         /* Try to instantiate from non-member functions.  */
  4808.         rhs = lookup_name_nonclass (name);
  4809.         if (rhs && TREE_CODE (rhs) == TREE_LIST)
  4810.           {
  4811.             /* This code seems to be missing a `return'.  */
  4812.             my_friendly_abort (4);
  4813.             instantiate_type (lhstype, rhs, complain);
  4814.           }
  4815.           }
  4816. #endif
  4817.       }
  4818.     if (complain)
  4819.       cp_error ("no compatible member functions named `%D'", name);
  4820.     return error_mark_node;
  4821.       }
  4822.  
  4823.     case CALL_EXPR:
  4824.       /* This is too hard for now.  */
  4825.       my_friendly_abort (183);
  4826.       return error_mark_node;
  4827.  
  4828.     case PLUS_EXPR:
  4829.     case MINUS_EXPR:
  4830.     case COMPOUND_EXPR:
  4831.       TREE_OPERAND (rhs, 0)
  4832.     = instantiate_type (lhstype, TREE_OPERAND (rhs, 0), complain);
  4833.       if (TREE_OPERAND (rhs, 0) == error_mark_node)
  4834.     return error_mark_node;
  4835.       TREE_OPERAND (rhs, 1)
  4836.     = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), complain);
  4837.       if (TREE_OPERAND (rhs, 1) == error_mark_node)
  4838.     return error_mark_node;
  4839.  
  4840.       TREE_TYPE (rhs) = lhstype;
  4841.       return rhs;
  4842.  
  4843.     case MULT_EXPR:
  4844.     case TRUNC_DIV_EXPR:
  4845.     case FLOOR_DIV_EXPR:
  4846.     case CEIL_DIV_EXPR:
  4847.     case ROUND_DIV_EXPR:
  4848.     case RDIV_EXPR:
  4849.     case TRUNC_MOD_EXPR:
  4850.     case FLOOR_MOD_EXPR:
  4851.     case CEIL_MOD_EXPR:
  4852.     case ROUND_MOD_EXPR:
  4853.     case FIX_ROUND_EXPR:
  4854.     case FIX_FLOOR_EXPR:
  4855.     case FIX_CEIL_EXPR:
  4856.     case FIX_TRUNC_EXPR:
  4857.     case FLOAT_EXPR:
  4858.     case NEGATE_EXPR:
  4859.     case ABS_EXPR:
  4860.     case MAX_EXPR:
  4861.     case MIN_EXPR:
  4862.     case FFS_EXPR:
  4863.  
  4864.     case BIT_AND_EXPR:
  4865.     case BIT_IOR_EXPR:
  4866.     case BIT_XOR_EXPR:
  4867.     case LSHIFT_EXPR:
  4868.     case RSHIFT_EXPR:
  4869.     case LROTATE_EXPR:
  4870.     case RROTATE_EXPR:
  4871.  
  4872.     case PREINCREMENT_EXPR:
  4873.     case PREDECREMENT_EXPR:
  4874.     case POSTINCREMENT_EXPR:
  4875.     case POSTDECREMENT_EXPR:
  4876.       if (complain)
  4877.     error ("invalid operation on uninstantiated type");
  4878.       return error_mark_node;
  4879.  
  4880.     case TRUTH_AND_EXPR:
  4881.     case TRUTH_OR_EXPR:
  4882.     case TRUTH_XOR_EXPR:
  4883.     case LT_EXPR:
  4884.     case LE_EXPR:
  4885.     case GT_EXPR:
  4886.     case GE_EXPR:
  4887.     case EQ_EXPR:
  4888.     case NE_EXPR:
  4889.     case TRUTH_ANDIF_EXPR:
  4890.     case TRUTH_ORIF_EXPR:
  4891.     case TRUTH_NOT_EXPR:
  4892.       if (complain)
  4893.     error ("not enough type information");
  4894.       return error_mark_node;
  4895.  
  4896.     case COND_EXPR:
  4897.       if (type_unknown_p (TREE_OPERAND (rhs, 0)))
  4898.     {
  4899.       if (complain)
  4900.         error ("not enough type information");
  4901.       return error_mark_node;
  4902.     }
  4903.       TREE_OPERAND (rhs, 1)
  4904.     = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), complain);
  4905.       if (TREE_OPERAND (rhs, 1) == error_mark_node)
  4906.     return error_mark_node;
  4907.       TREE_OPERAND (rhs, 2)
  4908.     = instantiate_type (lhstype, TREE_OPERAND (rhs, 2), complain);
  4909.       if (TREE_OPERAND (rhs, 2) == error_mark_node)
  4910.     return error_mark_node;
  4911.  
  4912.       TREE_TYPE (rhs) = lhstype;
  4913.       return rhs;
  4914.  
  4915.     case MODIFY_EXPR:
  4916.       TREE_OPERAND (rhs, 1)
  4917.     = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), complain);
  4918.       if (TREE_OPERAND (rhs, 1) == error_mark_node)
  4919.     return error_mark_node;
  4920.  
  4921.       TREE_TYPE (rhs) = lhstype;
  4922.       return rhs;
  4923.       
  4924.     case ADDR_EXPR:
  4925.       if (TYPE_PTRMEMFUNC_P (lhstype))
  4926.     lhstype = TYPE_PTRMEMFUNC_FN_TYPE (lhstype);
  4927.       else if (TREE_CODE (lhstype) != POINTER_TYPE)
  4928.     {
  4929.       if (complain)
  4930.         error ("type for resolving address of overloaded function must be pointer type");
  4931.       return error_mark_node;
  4932.     }
  4933.       TREE_TYPE (rhs) = lhstype;
  4934.       lhstype = TREE_TYPE (lhstype);
  4935.       {
  4936.     tree fn = instantiate_type (lhstype, TREE_OPERAND (rhs, 0), complain);
  4937.     if (fn == error_mark_node)
  4938.       return error_mark_node;
  4939.     mark_addressable (fn);
  4940.     TREE_OPERAND (rhs, 0) = fn;
  4941.     TREE_CONSTANT (rhs) = staticp (fn);
  4942.       }
  4943.       return rhs;
  4944.  
  4945.     case ENTRY_VALUE_EXPR:
  4946.       my_friendly_abort (184);
  4947.       return error_mark_node;
  4948.  
  4949.     case ERROR_MARK:
  4950.       return error_mark_node;
  4951.  
  4952.     default:
  4953.       my_friendly_abort (185);
  4954.       return error_mark_node;
  4955.     }
  4956. }
  4957.  
  4958. /* Return the name of the virtual function pointer field
  4959.    (as an IDENTIFIER_NODE) for the given TYPE.  Note that
  4960.    this may have to look back through base types to find the
  4961.    ultimate field name.  (For single inheritance, these could
  4962.    all be the same name.  Who knows for multiple inheritance).  */
  4963. static tree
  4964. get_vfield_name (type)
  4965.      tree type;
  4966. {
  4967.   tree binfo = TYPE_BINFO (type);
  4968.   char *buf;
  4969.  
  4970.   while (BINFO_BASETYPES (binfo)
  4971.      && TYPE_VIRTUAL_P (BINFO_TYPE (BINFO_BASETYPE (binfo, 0)))
  4972.      && ! TREE_VIA_VIRTUAL (BINFO_BASETYPE (binfo, 0)))
  4973.     binfo = BINFO_BASETYPE (binfo, 0);
  4974.  
  4975.   type = BINFO_TYPE (binfo);
  4976.   buf = (char *)alloca (sizeof (VFIELD_NAME_FORMAT)
  4977.             + TYPE_NAME_LENGTH (type) + 2);
  4978.   sprintf (buf, VFIELD_NAME_FORMAT, TYPE_NAME_STRING (type));
  4979.   return get_identifier (buf);
  4980. }
  4981.  
  4982. void
  4983. print_class_statistics ()
  4984. {
  4985. #ifdef GATHER_STATISTICS
  4986.   fprintf (stderr, "convert_harshness = %d\n", n_convert_harshness);
  4987.   fprintf (stderr, "compute_conversion_costs = %d\n", n_compute_conversion_costs);
  4988.   fprintf (stderr, "build_method_call = %d (inner = %d)\n",
  4989.        n_build_method_call, n_inner_fields_searched);
  4990.   if (n_vtables)
  4991.     {
  4992.       fprintf (stderr, "vtables = %d; vtable searches = %d\n",
  4993.            n_vtables, n_vtable_searches);
  4994.       fprintf (stderr, "vtable entries = %d; vtable elems = %d\n",
  4995.            n_vtable_entries, n_vtable_elems);
  4996.     }
  4997. #endif
  4998. }
  4999.  
  5000. /* Push an obstack which is sufficiently long-lived to hold such class
  5001.    decls that may be cached in the previous_class_values list.  For now, let's
  5002.    use the permanent obstack, later we may create a dedicated obstack just
  5003.    for this purpose.  The effect is undone by pop_obstacks.  */
  5004. void
  5005. maybe_push_cache_obstack ()
  5006. {
  5007.   push_obstacks_nochange ();
  5008.   if (current_class_depth == 1)
  5009.     current_obstack = &permanent_obstack;
  5010. }
  5011.